IsAuthenticated is false during LoggedIn event

Discussion in 'ASP .Net Security' started by James Coleman, Apr 16, 2006.

  1. I have forms authentication and a Login1_LoggedIn event handler that is
    called after the user successfully logs in (SqlMembershipProvider). I am
    trying to execute some additional code that takes into account a user's role.
    The problem is during this time IsAuthenticated and IsInRole are false. The
    wierd thing is that this only happens the first time through, if I refresh
    the page than the code works. Does it take a while for the user.identity to
    actually stick? Code snippet below:

    protected void Login1_LoggedIn(object sender, EventArgs e)
    {
    // if we get a Ticket from AuthenticateAsUser the credentials are
    valid
    //Ticket =
    CmsFormsAuthentication.AuthenticateAsUser(Login1.UserName, Login1.Password);
    if (Context.User.IsInRole("Admin"))
    {
    //Ticket =
    CmsFormsAuthentication.AuthenticateAsUser("WinNT://webacom/jcoleman",
    "`1q`1q");
    Ticket = CmsFormsAuthentication.AuthenticateAsUser("WinNT://" +
    WebConfigurationManager.AppSettings["ADMIN_USERNAME"],
    WebConfigurationManager.AppSettings["ADMIN_PASSWORD"]);
    }
    else if (Context.User.IsInRole("Dealer"))
    {
    Ticket = CmsFormsAuthentication.AuthenticateAsUser("WinNT://" +
    WebConfigurationManager.AppSettings["DEALER_USERNAME"],
    WebConfigurationManager.AppSettings["DEALER_PASSWORD"]);
    }
    {
    CmsFormsAuthentication.AuthenticateAsGuest();
    }
    if (Ticket != null)
    {
    CmsFormsAuthentication.SetAuthCookie(Ticket, false,
    Login1.RememberMeSet);
    }
    ProfileCommon prof = Profile.GetProfile(Login1.UserName);
    if (prof.TempPassword == "true")
    {
    prof.TempPassword = "false";
    prof.Save();
    Response.Redirect("ResetPassword.aspx?action=temp");
    }
    }

    Thanks for the help
    ~james
    --
    James Coleman
    Technical Director
    AGENCY.COM [Chicago]
     
    James Coleman, Apr 16, 2006
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Nick
    Replies:
    0
    Views:
    605
  2. Bob
    Replies:
    1
    Views:
    12,034
    Joe Fallon
    Apr 29, 2004
  3. ChInKPoInt [No MCSD]
    Replies:
    0
    Views:
    831
    ChInKPoInt [No MCSD]
    Dec 4, 2004
  4. Pascal
    Replies:
    0
    Views:
    488
    Pascal
    Aug 31, 2005
  5. James Coleman

    Context.User.IsAuthenticated = false?????

    James Coleman, Apr 10, 2006, in forum: ASP .Net Security
    Replies:
    1
    Views:
    344
    Dominick Baier [DevelopMentor]
    Apr 11, 2006
Loading...

Share This Page