0

i'm having some problem over here..when user enter their id and password,it will show up the main page and its for user but when admin or staff enter their id,it will enter the user's main page and i have to click admin site on the top hyperlink where it automatically logout and once i enter back admin passwrd or staff passwrd then only it redirect to admin page or staff page.how to make it like once user enter their passwrd it redirect to user page and once admin enter admin password or staff enter their password in the login it redirect to admin or staff ?I have 3 roles over here which are admin,staff and user.Hereby i'll provide you my aspx code and also my vb code which is running behind the program.please do assist me.thanks

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

End Class

please do guide me in this.need this urgent thanks.

4

1 に答える 1

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;
                        }
                    }
                }
    }
于 2011-11-09T15:00:44.390 に答える