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
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