简体   繁体   English

登录后,用户根据asp.net中的角色重定向其他页面

[英]After Login User redirect different Page according to Role In asp.net

but it's not working how to solve this problem 但是解决这个问题是行不通的

此图像显示“我的项目”文件夹的管理员,用户和客户

Main Web.Config file which contain all information about Authentication membership and role manager 主Web.Config文件,其中包含有关身份验证成员身份和角色管理器的所有信息

    <authentication mode="Forms">
  <forms cookieless="UseCookies"  path="/"

    loginUrl="Login/default.aspx"  protection="All" timeout="30">
  </forms>
</authentication>

<membership defaultProvider="Demo_MemberShipProvider">
  <providers>
    <add name="Demo_MemberShipProvider"

        type="System.Web.Security.SqlMembershipProvider"

        connectionStringName="cs"

        enablePasswordRetrieval="false"

        enablePasswordReset="true"

        requiresQuestionAndAnswer="true"

        applicationName="/"

        requiresUniqueEmail="false"

        passwordFormat="Hashed"

        maxInvalidPasswordAttempts="5"

        minRequiredPasswordLength="5"

        minRequiredNonalphanumericCharacters="0"

        passwordAttemptWindow="10" passwordStrengthRegularExpression=""/>
  </providers>
</membership>

<roleManager enabled="true" cacheRolesInCookie="true"

cookieName="TBHROLES" defaultProvider="Demo_RoleProvider">
  <providers>
    <add connectionStringName="cs"

    applicationName="/" name="Demo_RoleProvider"

    type="System.Web.Security.SqlRoleProvider, System.Web,
              Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
  </providers>
</roleManager>



      <!--Admin Web.Config-->
  <authorization>
    <allow roles="Admin" />
    <deny roles="User, Customer"/>
    <deny users="?"/>
  </authorization>
  <!--Customer Web.Config-->
  <authorization>
    <allow roles="Admin, User, Customer" />
    <deny users="?"/>
  </authorization>
  <!--User Web.Config-->
  <authorization>
    <allow roles="Admin, User" />
    <deny roles="Customer"/>
    <deny users="?"/>
  </authorization>

This is Login button Code for login 这是登录按钮登录代码

protected void Login1_Authenticate(object sender, AuthenticateEventArgs e)
{
    if (Membership.ValidateUser(Login1.UserName, Login1.Password) == true)
    {
        Login1.Visible = true;
        Session["user"] = User.Identity.Name;
        FormsAuthentication.RedirectFromLoginPage(Login1.UserName, true);
    }
    else
    {

        Response.Write("Invalid Login");
    }
}
 protected void Login1_Authenticate(object sender, AuthenticateEventArgs e)
    {
        if (Membership.ValidateUser(Login1.UserName, Login1.Password) == true)
        {
            Login1.Visible = true;
            Session["user"] = User.Identity.Name;

            var userRoles = Roles.GetRolesForUser(Login1.UserName);
            var userIdentity = new GenericIdentity(Login1.UserName);
            var principal = new GenericPrincipal(userIdentity, userRoles);

            Context.User = principal;

            if (User.IsInRole("Admin"))
                Response.Redirect("~/ThePageForAdmin");

            if (User.IsInRole("User"))
                Response.Redirect("~/ThePageForUser");

            if (User.IsInRole("Customer"))
                Response.Redirect("~/ThePageForCustomer");
        }
        else
        {

            Response.Write("Invalid Login");
        }
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何根据用户在Asp.net C#中的角色将用户从登录页面重定向到下一页 - how to redirect user from login page to next page base on their Role in Asp.net C# 根据ASP.NET MVC 4 Internet应用程序登录中的用户角色重定向到其他页面 - redirect to different pages based on user role in ASP.NET MVC 4 Internet Application Login 我在ASP.net中登录时如何根据用户重定向页面? - How to redirect the page according to user when I login in ASP.net? 登录后如何使用asp.net中的角色管理重定向用户? - How to redirect user after login using role management in asp.net? ASP.NET成员身份按用户角色重定向到页面 - ASP.NET membership redirect to a page by user role 如何在 .ASP.NET Core MVC 中使用多个登录页面和未经授权的用户重定向不同的登录页面 - How to use multiple login pages in .ASP.NET Core MVC and unauthorized user redirect different login page 登录asp.net后重定向其他页面,然后重定向主页 - Redirect other page then Home page after login in asp.net 在asp.net中限制用户后如何将用户重定向到登录页面 - how to redirect user to login page after restricting them in asp.net 在asp.net中成功登录后,将用户重定向到源页面 - Redirect the user back to the source page from where it has come after succesfull login in asp.net 在asp.net 4.0中登录后重定向页面 - Redirect Page after Login in asp.net 4.0
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM