TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
umair mohsin
1k
387
65.7k
how to set roles in mvc
Mar 30 2021 12:26 PM
i have two different tables in my application named user one and user two.i want to stop user one users to see users two index page and vice versa.how may i apply this customrole.both index pages are protected with [Authorize(roles="one/two")].
when debugging moves to customprovider.cs one becomes null and other found that null refrence exception i could not handle.please help me.
here is my customprovider.cs code
public
override
void
AddUsersToRoles(
string
[] usernames,
string
[] roleNames)
{
throw
new
NotImplementedException();
}
public
override
string
ApplicationName
{
get
{
throw
new
NotImplementedException();
}
set
{
throw
new
NotImplementedException();
}
}
public
override
void
CreateRole(
string
roleName)
{
throw
new
NotImplementedException();
}
public
override
bool
DeleteRole(
string
roleName,
bool
throwOnPopulatedRole)
{
throw
new
NotImplementedException();
}
public
override
string
[] FindUsersInRole(
string
roleName,
string
usernameToMatch)
{
throw
new
NotImplementedException();
}
public
override
string
[] GetAllRoles()
{
throw
new
NotImplementedException();
}
public
override
string
[] GetRolesForUser(
string
username)
{
DBEntities db =
new
DBEntities();
string
s = db.user1.Where(x => x.Email == username).FirstOrDefault().UserRole;
string
s1 = db.user2.Where(x => x.Email == username).FirstOrDefault().UserRole;
if
(s ==
null
)
{
string
[] res1 = { s1 };
try
{
return
res1;
}
catch
(Exception e)
{
e.ToString();
}
return
res1;
}
else
{
string
[] res1 = { s };
try
{
return
res1;
}
catch
(Exception e)
{
e.ToString();
}
return
res1;
}
}
public
override
string
[] GetUsersInRole(
string
roleName)
{
throw
new
NotImplementedException();
}
public
override
bool
IsUserInRole(
string
username,
string
roleName)
{
throw
new
NotImplementedException();
}
public
override
void
RemoveUsersFromRoles(
string
[] usernames,
string
[] roleNames)
{
throw
new
NotImplementedException();
}
public
override
bool
RoleExists(
string
roleName)
{
throw
new
NotImplementedException();
}
Reply
Answers (
2
)
Delete record in abstract table using webapi
.net mvc form-data api call