0

我在這裏遇到了一些問題..當用戶輸入他們的ID和密碼時,它會顯示主頁面和用戶的身份,但是當管理員或員工輸入他們的ID時,它會進入用戶的主頁,我必須點擊頂部超鏈接上的管理站點,它會自動註銷,並且一旦我輸入管理員密碼或員工密碼,那麼只有它重定向到管理頁面或員工頁面。如果用戶輸入他們的密碼它重定向到用戶頁面,一旦管理員輸入管理員密碼或工作人員在登錄時輸入密碼重定向到管理員或員工?我有3個角色在這裏是管理員,工作人員和用戶。在此我將爲您提供我的aspx代碼和也是我的vb代碼,它運行在程序後面。請幫助我。謝謝根據用戶的角色重定向

ASPX

<asp:Login ID="Login1" runat="server" BackColor="#009933" BorderColor="Red" 
    BorderPadding="4" BorderStyle="Ridge" BorderWidth="1px" Font-Names="Verdana" 
    Font-Size="0.8em" ForeColor="Red" 
    DestinationPageUrl="~/MainPage.aspx" style="text-align: center" Height="171px" 
       Width="266px" VisibleWhenLoggedIn="True" TextLayout="TextOnTop"> 
    <TextBoxStyle Font-Size="0.8em" /> 
    <LoginButtonStyle BackColor="#FFFBFF" BorderColor="#CCCCCC" BorderStyle="Solid" 
     BorderWidth="1px" Font-Names="Verdana" Font-Size="0.8em" ForeColor="#284775" /> 
    <InstructionTextStyle Font-Italic="True" ForeColor="Black" /> 
    <TitleTextStyle BackColor="#5D7B9D" Font-Bold="True" Font-Size="0.9em" 
     ForeColor="White" /> 

</asp:Login> 

VB

Partial Class Login 

Inherits System.Web.UI.Page 

末級

請你指導我this.need這一緊迫的感謝。

+0

複製到http://stackoverflow.com/questions/8066085/redirecting-admin-to-admin-page-and-user-to-users-page?! –

回答

0

,如果你不想要進入ASP會員,在這裏可以是一個簡單的解決方案: 基於URL如果請求來自您可以在Login.aspx.cs網頁編寫代碼:

protected void LoginButton_Click(object sender, EventArgs e) 
    { 
     //I detect where the request originated from 
     string str = Request.QueryString["ReturnUrl"] == null ? "" : Request.QueryString["ReturnUrl"].ToString(); 
      //if this is Admin can access to Admin Area only 
      if (str.Contains("Admin") == true || str.Contains("admin") == true || str.Contains("ADMIN") == true) 
       { 
        string[] UserNameCollection = { "Admin" }; 
        string[] PasswordCollection = { "admin" }; 

        for (int Iterator = 0; Iterator <= UserNameCollection.Length - 1; Iterator++) 
        { 
         bool UserNameIsValid = (string.Compare(UserName.Text, UserNameCollection[Iterator], true) == 0); 
         bool PasswordIsValid = (string.Compare(Password.Text, PasswordCollection[Iterator], false) == 0); 

         if (UserNameIsValid && PasswordIsValid) 
         { 

          FormsAuthentication.SetAuthCookie(UserName.Text, true); 
          Response.Redirect("Admin/Default.aspx"); 
         } 
         else 
         { 
          BadCredentials.Text = "Not valid"; 
          BadCredentials.Visible = true; 
         } 
        } 
       } 
      //if this is a crm user can access to Crm Area only 
      else if (str.Contains("Staff") == true) 
      { 
        string[] UserNameCollection = { "Staff" }; 
        string[] PasswordCollection = { "staff" }; 

        for (int Iterator = 0; Iterator <= UserNameCollection.Length - 1; Iterator++) 
        { 
         bool UserNameIsValid = (string.Compare(UserName.Text, UserNameCollection[Iterator], true) == 0); 
         bool PasswordIsValid = (string.Compare(Password.Text, PasswordCollection[Iterator], false) == 0); 

         if (UserNameIsValid && PasswordIsValid) 
         { 
          SaveVisitedEntry("CrmAdmin"); 
          FormsAuthentication.SetAuthCookie(UserName.Text, true); 
          Response.Redirect("Staff/Default.aspx"); 
         } 
         else 
         { 
          BadCredentials.Text = "Not valid"; 
          BadCredentials.Visible = true; 
         } 
        } 
       } 
    } 
+0

我無法運行Protected void LoginButton_Click(對象發件人,EventArgs e)它說LoginButton_Click(對象發件人,EventArgs e)的語法錯誤,我已經嘗試了很多保護無效也永遠work.so作爲字符串str.please確實協助預先感謝 –

+0

以及我沒有提到它,但這是響應按鈕單擊事件的代碼背後的代碼: enricoariel

+0

這是您的基本控制需要在login.aspx的文件:

請登錄

用戶名:

密碼:

enricoariel

相關問題