這似乎應該是如此簡單,但即使淘計算器後,我無法弄清楚。將用戶重定向到頁面,根據自己的角色
我有一個非常標準的登錄控制:
<asp:Login ID="LoginUser" runat="server" EnableViewState="false" RenderOuterTable="false">
<LayoutTemplate>
<span class="failureNotification">
<asp:Literal ID="FailureText" runat="server"></asp:Literal>
</span>
<asp:ValidationSummary ID="LoginUserValidationSummary" runat="server" CssClass="failureNotification"
ValidationGroup="LoginUserValidationGroup"/>
<div class="accountInfo">
<fieldset class="login">
<legend>Account Information</legend>
<p>
<asp:Label ID="UserNameLabel" runat="server" AssociatedControlID="UserName">Username:<span class="required"> *</span></asp:Label>
<asp:TextBox ID="UserName" runat="server" CssClass="textEntry"></asp:TextBox>
<asp:RequiredFieldValidator ID="UserNameRequired" runat="server" ControlToValidate="UserName"
CssClass="failureNotification" ErrorMessage="User Name is required." ToolTip="User Name is required."
ValidationGroup="LoginUserValidationGroup">*</asp:RequiredFieldValidator>
</p>
<p>
<asp:Label ID="PasswordLabel" runat="server" AssociatedControlID="Password">Password:<span class="required"> *</span></asp:Label>
<asp:TextBox ID="Password" runat="server" CssClass="passwordEntry" TextMode="Password"></asp:TextBox>
<asp:RequiredFieldValidator ID="PasswordRequired" runat="server" ControlToValidate="Password"
CssClass="failureNotification" ErrorMessage="Password is required." ToolTip="Password is required."
ValidationGroup="LoginUserValidationGroup">*</asp:RequiredFieldValidator>
</p>
<p>
<asp:CheckBox ID="RememberMe" runat="server" />
<asp:Label ID="RememberMeLabel" runat="server" AssociatedControlID="RememberMe" CssClass="inline">Keep me logged in</asp:Label>
</p>
</fieldset>
<p class="submitButton">
<asp:Button ID="LoginButton" runat="server" CommandName="Login" Text="Log In" ValidationGroup="LoginUserValidationGroup"/>
</p>
<p><asp:HyperLink ID="ResetLink" runat="server" NavigateUrl="~/ResetPassword.aspx">Forgot password?</asp:HyperLink></p>
</div>
</LayoutTemplate>
用下面是我的代碼隱藏:
Protected Sub LoginUser_LoggedIn(sender As Object, e As System.EventArgs) Handles LoginUser.LoggedIn
If User.IsInRole("SuperAdmins") Then
Me.LoginUser.DestinationPageUrl = "~/Staff/Default.aspx"
ElseIf User.IsInRole("Admins") Then
Me.LoginUser.DestinationPageUrl = "~/Admin/Default.aspx"
ElseIf User.IsInRole("Teachers") Then
Me.LoginUser.DestinationPageUrl = "~/Teacher/Default.aspx"
ElseIf User.IsInRole("Providers") Then
Me.LoginUser.DestinationPageUrl = "~/Provider/Default.aspx"
Else
Me.LoginUser.DestinationPageUrl = "~"
End If
End Sub
目前,我總是重定向到 「〜」 連儘管我以SuperAdmin身份登錄。我確定我在錯誤的地方檢查'IsInRole',但我不知道該在哪裏做。我重定向後,我確實登錄。
這是我的第一個「問題」,所以希望我提供正確的信息。
更多信息......下面代碼沒有工作:
Protected Sub LoginUser_LoggedIn(sender As Object, e As System.EventArgs) Handles LoginUser.LoggedIn
If (Roles.IsUserInRole(LoginUser.UserName, "SuperAdmins")) Then
Me.LoginUser.DestinationPageUrl = "~/Staff/Default.aspx"
ElseIf (Roles.IsUserInRole(LoginUser.UserName, "Admins")) Then
Me.LoginUser.DestinationPageUrl = "~/Admin/Default.aspx"
ElseIf (Roles.IsUserInRole(LoginUser.UserName, "Teachers")) Then
Me.LoginUser.DestinationPageUrl = "~/Teacher/Default.aspx"
ElseIf (Roles.IsUserInRole(LoginUser.UserName, "Providers")) Then
Me.LoginUser.DestinationPageUrl = "~/Provider/Default.aspx"
Else
Me.LoginUser.DestinationPageUrl = "~"
End If
末次