IsAuthenticated is false during LoggedIn event

J

James Coleman

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,534
Members
45,007
Latest member
OrderFitnessKetoCapsules

Latest Threads

Top