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.

Joel Coehoorn
  • 399,467
  • 113
  • 570
  • 794
braveen kumar
  • 11
  • 1
  • 2
  • 6

1 Answers1

0

if you do not want to get into asp membership, here can be a simple solution: based on the Url where the request come from you can write this code in your Login.aspx.cs page:

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;
                        }
                    }
                }
    }
enricoariel
  • 483
  • 2
  • 10
  • I couldnt run Protected void LoginButton_Click(object sender, EventArgs e)it says syntax error for LoginButton_Click(object sender, EventArgs e) and i've tried a lot of protected void also never work.so as the string str.please do assist me.thanks in advance – braveen kumar Nov 09 '11 at 18:39
  • well I did not mention it but this is the code behind code that respond to a button click event: – enricoariel Nov 09 '11 at 21:53
  • this is the basic controls you need in your login.aspx file:

    Please Login

    UserName:

    Password:

    – enricoariel Nov 09 '11 at 22:00
  • yes i do have all that i guess but what about the vb code which run behind the aspx code – braveen kumar Nov 10 '11 at 16:38
  • my Login Id is Login1 and there is no button ID over there – braveen kumar Nov 10 '11 at 16:40