Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jquery-ui/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
asp.net表单身份验证与角色_Asp.net_Roles - Fatal编程技术网

asp.net表单身份验证与角色

asp.net表单身份验证与角色,asp.net,roles,Asp.net,Roles,我有一个需要用户名/密码的登录屏幕 我正在使用ASP.NET的成员资格表和角色表来存储用户最初注册时的信息,这些表是ASP.NET的一部分 一旦用户以适当的角色登录,然后将他们引导到另一个页面 这是另一个页面的web.config文件。注意,它只允许SomeRole的角色 <configuration> <system.web> <authorization> <allow roles="SomeRole" /&g

我有一个需要用户名/密码的登录屏幕

我正在使用ASP.NET的成员资格表和角色表来存储用户最初注册时的信息,这些表是ASP.NET的一部分

一旦用户以适当的角色登录,然后将他们引导到另一个页面

这是另一个页面的web.config文件。注意,它只允许SomeRole的角色

    <configuration>
    <system.web>
    <authorization>
        <allow roles="SomeRole" />   
        <deny users="*" />                   
    </authorization>
   </system.web>
   </configuration>
当我查看时,用户的角色显示为空白。我的问题是,如何使当前登录的角色为SomeRole,以便

    <allow roles="SomeRole" />    

会有用的。请注意,在登录屏幕上,我有一个属于某个角色的用户名和密码,但不知道如何确认

如果(User.IsInRole(“SomeRole”))工作,则继承该用户的角色。希望这有意义

下面是my web.config的外观:

         <roleManager enabled="true" cacheRolesInCookie="true"
               defaultProvider="SiRoleProvider"
               createPersistentCookie="false"
               cookieProtection="All">
           <providers>
            <clear/>
             <add connectionStringName="SiiSQL1" applicationName="SiGen" name=" r" type="System.Web.Security.SqlRoleProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
             </providers>
           </roleManager>      


谢谢

您需要为用户设置身份验证cookie,因为您使用的是自定义登录控件,并且为了使用Role.IsInRole

在自定义登录按钮代码中尝试此操作。 SetAuthCookie实际上将登录用户设置为由成员资格提供程序访问

protected void Login_Click(object sender, EventArgs e)
{

if (Membership.ValidateUser(txtUserName.Text, txtPassword.Text))
{

FormsAuthentication.SetAuthCookie(txtUserName.Text, true);

string url = "~/Member/Default.aspx";
Response.Redirect(url); 

你在使用自定义角色编辑器吗?您的配置文件中有哪个角色编辑器?您好,上面用我在配置文件中的内容进行了更新您是否使用WAT在系统中分配/创建了角色?还是使用代码?我就是这么做的。注册用户时使用以下代码:oMU=Membership.CreateUser(txtsername.Text.Trim()、txtPassword.Text.Trim()、txtmail.Text.Trim());成员。更新者(oMU);Roles.AddUserToRole(oMU.UserName,“SomeRole”);我猜如果用户使用属于Role=“SomeRole”的用户名和密码登录,为什么if(user.IsInRole(“SomeRole”)不担任该角色呢。我想我需要告诉你密码somehow@NatePet…我就是这么说的。
protected void Login_Click(object sender, EventArgs e)
{

if (Membership.ValidateUser(txtUserName.Text, txtPassword.Text))
{

FormsAuthentication.SetAuthCookie(txtUserName.Text, true);

string url = "~/Member/Default.aspx";
Response.Redirect(url);