2012-03-19 66 views
0

我正在嘗試在我的系統中創建一個訪問角色。我有這兩個角色;管理員和用戶。在我的登錄頁面,我就把這行代碼:角色重定向中的錯誤

 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,它給了我這個錯誤,

資源無法找到。 描述:HTTP 404.您正在查找的資源(或其某個依賴項)可能已被刪除,名稱已更改或暫時不可用。請檢查以下網址並確保它拼寫正確。 請求的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" /> 

我想我已經檢查了名,並透過所有編碼了這麼多次去了。有什麼我可以做的,以解決這個問題?謝謝。

+1

你有所有的頁面你在這裏參考? – PraveenVenu 2012-03-19 04:11:22

+0

Yeap。我做。雙重檢查它。但仍然是相同的錯誤 – 2012-03-19 04:12:11

+0

您是否嘗試過使用瀏覽器開發工具之一瀏覽代碼,以查看其重定向到哪個頁面或使用瀏覽器開發工具監視瀏覽器中的網絡流量? – 2012-03-19 04:14:04

回答

0

參考這個 - Examining ASP.NET's Membership, Roles, and Profile
嘗試配置您的角色管理器爲:

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

,並在登錄按鈕檢查用戶角色:參考:Validation on current user

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

還是不行。無法找到該資源。我不明白爲什麼不能找到。 – 2012-03-19 05:33:07

+0

你運行管理網站來配置成員資格數據庫???檢查部分.. – 2012-03-19 05:39:02

+0

是的。之前完成。 – 2012-03-19 05:44:29