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

相关问题