Link to home
Create AccountLog in
Avatar of robaherne
robaherne

asked on

Problem redirecting from login page

I have a Login control with an LoggedIn event that redirects the user based on their role.

The problem is the first time I log in it tries to redirect me to Default.aspx, which doesn't exist. But if I go back in the browser and log in again it redirects me to the appropriate page. Whats going on?!

Thanks.

CODE:

protected void Button1_Click(object sender, EventArgs e)
    {
        // Validate the user against the Membership framework user store      
        if (Membership.ValidateUser(txt_Name.Text, txt_Password.Text))      
        {          
            // Log the user into the site          
            FormsAuthentication.GetAuthCookie(txt_Name.Text, chk_RememberMe.Checked);
           
        }      
        //  user's credentials were invalid      
        lbl_InvalidMessage.Visible = true;
    }


    protected void OnLoggedIn(object sender, EventArgs e)
    {
        System.Threading.Thread.Sleep(3000);
        if (User.IsInRole("Band"))
        {
            Response.Redirect("~/PageBand.aspx");

        }
        else if (User.IsInRole("Venue"))
        {
            Response.Redirect("~/PageVenue.aspx");
        }
    }
Avatar of Avodah
Avodah
Flag of United Kingdom of Great Britain and Northern Ireland image

The IsAuthenticated status of the user has not been set therefore the user is not yet accessible in that fashion. Set a break point and evaluate the conditions User.IsInRole("Band") & User.IsInRole("Venue").

You can probably do this by getting the user using the UserName using Membership.FindUsersByName
Avatar of robaherne
robaherne

ASKER

Sorry I don't know what you mean by setting a break point... where would I do that?
ASKER CERTIFIED SOLUTION
Avatar of robaherne
robaherne

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
Congrats. You would expect in the OnLoggedIn event the user would have been logged in already. Oh well.