本文介绍了错误的作用重定向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图让我的系统访问的作用。我有这两个角色;管理员和用户。在我的登录页面,我把这个线code的:

I am trying to make an access role in my system. I have these two roles ; Admin and user. In my login page, I put this line of code:

        if (Roles.IsUserInRole(Login1.UserName, "Administrator"))
            Response.Redirect("~/4_Admin/Page1.aspx");
        else if (Roles.IsUserInRole(Login1.UserName, "Users"))
            Response.Redirect("~/3_User/Expense.aspx");

当用户角色登录,它们被定向到正确的页面,但为admin,它给了我这个错误,

When user role logged in, they are directed to the correct page but for the admin, it gives me this error,

资源无法找到。
说明:HTTP 404。您正在寻找(或它的一个依赖)可能已被删除的资源,更名或暂时不可用。请检查以下URL并确保其拼写正确。
请求的URL:/Self_studies/login.aspx

 <membership>
    <providers>
      <clear/>
      <add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider" connectionStringName="Connection" requiresQuestionAndAnswer="false" requiresUniqueEmail="false" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" applicationName="SampleApplication"/>
    </providers>
  </membership>
  <profile>
    <providers>
      <clear/>
      <add name="AspNetSqlProfileProvider" type="System.Web.Profile.SqlProfileProvider" connectionStringName="Connection" applicationName="SampleApplication"/>
    </providers>
  </profile>
  <roleManager enabled="true">
    <providers>
      <clear />
      <add connectionStringName="Connection" applicationName="SampleApplication"
        name="AspNetSqlRoleProvider" type="System.Web.Security.SqlRoleProvider" />
    </providers>
  </roleManager>
    <compilation debug="false">

      <assemblies>
        <add assembly="System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
        <add assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
        <add assembly="System.Data.DataSetExtensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
        <add assembly="System.Xml.Linq, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
      </assemblies>

    </compilation>
    <!--
        The <authentication> section enables configuration 
        of the security authentication mode used by 
        ASP.NET to identify an incoming user. 
    -->
    <authentication mode="Forms" />

我想我已经检查了名称,并通过所有编码这么多次了。有什么我可以做些什么来解决这个问题?谢谢你。

I think I have checked the name and went through all the coding for so many times. Is there anything that I can do to fix this? Thank you.

推荐答案

这 - 参考结果
尝试配置您的角色管理器为:

Reference this- Examining ASP.NET's Membership, Roles, and Profile
try to configure your role manager as:

<roleManager enabled="true"
                 defaultProvider="CustomizedRoleProvider">
      <providers>
         <add name="CustomizedRoleProvider"
              type="System.Web.Security.SqlRoleProvider"
              connectionStringName="MyDB"
              applicationName="/" />
      </providers>
    </roleManager>

在登录按钮检查用户角色为:参考:在当前用户验证

 if (HttpContext.Current.User.IsInRole("Administrators"))
        Response.Redirect("~/PageA.aspx");
    else
        Response.Redirect("~/PageB.aspx");

这篇关于错误的作用重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-18 12:50