Roles.IsUserInRole():名称IsUserInRole在asp.net mvc4的当前上下文中不存在

时间:2021-09-20 15:03:13

I am using asp.net mvc4 to create authentication and authorization application ,and i have created a common login page for all users in different roles(authentication and authorization is based on role),it should ask for username and password and when we click on login button it should check the user's role in database,and i am checking that as in below code

我使用asp.net mvc4创建身份验证和授权应用程序,我为不同角色的所有用户创建了一个通用登录页面(身份验证和授权基于角色),它应该要求输入用户名和密码,当我们点击时登录按钮它应检查用户在数据库中的角色,我正在检查,如下面的代码

But here its not entering in the if part,and also i have checked using add watch so it say's: IsUserInRole -The name 'IsUserInRole' does not exist in the current context

但是这里没有进入if部分,而且我已经使用add watch进行了检查,所以它说:IsUserInRole - 当前上下文中不存在名称'IsUserInRole'

I am using simple membership provider and want to built application using built-in methods and i have configured all in web.config

我使用简单的成员资格提供程序,并希望使用内置方法构建应用程序,我已在web.config中配置了所有

I am not able to figure whats the problem,i have read/searched many articles,any help would be greatly appreciated, pls help me.

我无法确定问题是什么,我已经阅读/搜索了很多文章,我们将非常感谢任何帮助,请帮助我。

if(Roles.IsUserInRole(WebSecurity.CurrentUserName,"Admin")) 
{
  RedirectToAction("Admin","Home");
}

1 个解决方案

#1


1  

IsUserInRole sits in the System.Web.Security namespace and you'll have to reference System.Web.dll to use it.

IsUserInRole位于System.Web.Security命名空间中,您必须引用System.Web.dll才能使用它。

http://msdn.microsoft.com/en-us/library/4z6b5d42.aspx

http://msdn.microsoft.com/en-us/library/4z6b5d42.aspx

#1


1  

IsUserInRole sits in the System.Web.Security namespace and you'll have to reference System.Web.dll to use it.

IsUserInRole位于System.Web.Security命名空间中,您必须引用System.Web.dll才能使用它。

http://msdn.microsoft.com/en-us/library/4z6b5d42.aspx

http://msdn.microsoft.com/en-us/library/4z6b5d42.aspx