RE: Forms Authentication - Sudden Redirect Failure on Login
- From: Stephen Davies <StephenDavies@xxxxxxxxxxxxx>
- Date: Mon, 17 Jul 2006 05:31:02 -0700
Didn't have the methods header on the last post so here is it complete:
/// <summary>
/// The central core for processing the forms authentication
/// This has been located in the common PageBase to allow
/// external function to call it and automatically log the
/// user into the system.
/// </summary>
/// <param name="redirectURL"></param>
/// <param name="role"></param>
/// <param name="strUser"></param>
protected void FormsAuthCore(string redirectURL, string role, string
strUser, bool bPersistant)
{
DateTime dtTimeout;
if (bPersistant)
dtTimeout = DateTime.Now.AddMonths(6);
else
dtTimeout = DateTime.Now.AddMinutes(60);
FormsAuthentication.Initialize();
FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(
1, // Ticket version
strUser.ToUpper(), // Username associated with ticket
DateTime.Now, // Date/time issued
dtTimeout, // Date/time to expire
bPersistant, // "true" for a persistent user cookie
role, // User-data, in this case the roles
FormsAuthentication.FormsCookiePath); // Path cookie valid for
// Encrypt the cookie using the machine key for secure transport
string hash = FormsAuthentication.Encrypt(ticket);
HttpCookie cookie = new HttpCookie(FormsAuthentication.FormsCookieName,
hash);
// Set the cookie's expiration time to the tickets expiration time
if (ticket.IsPersistent) cookie.Expires = ticket.Expiration;
// Add the cookie to the list for outgoing response
Response.Cookies.Add(cookie);
if (redirectURL == null || redirectURL == "noRedirect") return;
// Don't call FormsAuthentication.RedirectFromLoginPage since it could
// replace the authentication ticket (cookie) we just added
// string fred = FormsAuthentication.GetRedirectUrl(strUser, false);
// Debug.WriteLine("FormsAuthCore GetRedirectURL (not used) ->" + fred);
Debug.WriteLine("FormsAuthCore set cookie lastlogin->" + strUser.ToUpper());
SetCookie("lastlogin", strUser.ToUpper());
Debug.WriteLine("FormsAuthCore - Redirect to ->" + redirectURL);
Response.Redirect(redirectURL);
}
--
Regards
Stephen Davies
"Luke Zhang [MSFT]" wrote:
Hello Stephen,.
Could you please show us the code you used for form authentication, for
example, how did you call RedirectFromLoginPage method in your code? Is
CookiePath specified in the method?
Thanks,
Luke Zhang
Microsoft Online Community Lead
==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
- References:
- RE: Forms Authentication - Sudden Redirect Failure on Login
- From: Luke Zhang [MSFT]
- RE: Forms Authentication - Sudden Redirect Failure on Login
- From: Luke Zhang [MSFT]
- RE: Forms Authentication - Sudden Redirect Failure on Login
- From: Luke Zhang [MSFT]
- RE: Forms Authentication - Sudden Redirect Failure on Login
- Prev by Date: RE: Forms Authentication - Sudden Redirect Failure on Login
- Next by Date: Problems with changepassword control
- Previous by thread: RE: Forms Authentication - Sudden Redirect Failure on Login
- Next by thread: Overloading security check on dropdown, is it possible??
- Index(es):
Relevant Pages
|
|