简体   繁体   English

授权用户无法访问他们的页面

[英]authorized users cannot access their page

I have a application that authenticates a particular user(East) and redirects them to their respective page(East.aspx).This page cannot be displayed to un-authorized users, whenever they go to the authorized page(East.aspx) they are re-directed to the login page.我有一个应用程序可以验证特定用户(East)并将他们重定向到各自的页面(East.aspx)。这个页面不能显示给未经授权的用户,只要他们 go 到授权页面(East.aspx)他们是重定向到登录页面。

To solve the above problem I have created roles and added users to a particular role in Application file(Global.asax) in Application_Start Event.为了解决上述问题,我创建了角色并将用户添加到 Application_Start 事件中的应用程序文件(Global.asax)中的特定角色中。

void Application_Start(object sender, EventArgs e) 
{
    // Code that runs on application startup
    if (Roles.RoleExists("Browser") == false)
    {
        Roles.CreateRole("Browser");
        Roles.AddUserToRole("East","Browser");
    }
    if (Roles.RoleExists("Buyer") == false)
    {
        Roles.CreateRole("Buyer");
        Roles.AddUserToRole("B2","Buyer");
    }
    if (Roles.RoleExists("Seller") == false)
    {
        Roles.CreateRole("Seller");
        Roles.AddUserToRole("S1","Seller");
    }
    if (Roles.RoleExists("Admin") == false)
    {
        Roles.CreateRole("Admin");
        Roles.AddUserToRole("A1","Admin");
    }

}

In web.Config file I implemented following在 web.Config 文件中,我实现了以下

</authorization>

<roleManager enabled="true" defaultProvider="SqlRoleManager">
  <providers>
    <clear/>
    <add name="SqlRoleManager" type="System.Web.Security.SqlRoleProvider" connectionStringName="MyDbConn" applicationName="RolebasedApp"/>
    <add applicationName="RolebasedApp" name="AspNetWindowsTokenRoleProvider" type="System.Web.Security.WindowsTokenRoleProvider"/>
  </providers>
</roleManager>
</system.web>

I'm testing the above case for only East User.I want to make sure that my Application name is (the application name where I start creating the Web pages for different users).我只为东方用户测试上述案例。我想确保我的应用程序名称是(我开始为不同用户创建 Web 页面的应用程序名称)。

When all of this is done, when I run my application And enter the correct credentials for User "East".完成所有这些后,当我运行我的应用程序并为用户“East”输入正确的凭据时。 I get Navigated to Login page instead of East.aspx我导航到登录页面而不是 East.aspx

How can this be solved?如何解决?

You need a configuration that looks like this:您需要一个如下所示的配置:

  <location path="East.aspx">
    <system.web>
      <authorization>
        <deny users="?" />         <!--Deny all Anonymous (not logged in) users-->
        <allow roles="east"/>        <!--Permit users in these roles-->
        <deny users="*"/>        <!--Deny all users-->
      </authorization>
    </system.web>
  </location>

You can skip the location tag if east.aspx is in a separate folder and the folder has its own web.config file.如果 east.aspx 位于单独的文件夹中并且该文件夹有自己的 web.config 文件,则可以跳过位置标记。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM