Click here to Skip to main content
15,914,943 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi
Forms authentication is working in IE on production server. Its working fine in local machine.

I am accessing production server by IP address.

Here is my code
C#
HttpResponse pageResponse = HttpContext.Current.Response;


Guid sessionToken = System.Guid.NewGuid();


HttpCookie authenticationCookie =
    pageResponse.Cookies[FormsAuthentication.FormsCookieName];
FormsAuthenticationTicket authenticationTicket =
    FormsAuthentication.Decrypt(authenticationCookie.Value);

authenticationCookie.Expires.AddMinutes(15);

FormsAuthenticationTicket newAuthenticationTicket =
    new FormsAuthenticationTicket(
    1,
    authenticationTicket.Name,
    authenticationTicket.IssueDate,
    authenticationTicket.Expiration,
    authenticationTicket.IsPersistent,
    sessionToken.ToString(),
    FormsAuthentication.FormsCookieName);


pageResponse.Cookies.Remove(FormsAuthentication.FormsCookieName);



HttpCookie newAuthenticationCookie = new HttpCookie(
    FormsAuthentication.FormsCookieName,
    FormsAuthentication.Encrypt(newAuthenticationTicket));

newAuthenticationCookie.HttpOnly = authenticationCookie.HttpOnly;
newAuthenticationCookie.Path = authenticationCookie.Path;
newAuthenticationCookie.Secure = authenticationCookie.Secure;
newAuthenticationCookie.Domain = authenticationCookie.Domain;
newAuthenticationCookie.Expires = DateTime.Now.AddMinutes(15);

pageResponse.Cookies.Add(newAuthenticationCookie);
Posted
Updated 5-Jun-13 5:26am
v2
Comments
ZurdoDev 5-Jun-13 11:27am    
What does your web.config authentication tag look like?
Imran Khan Pathan 5-Jun-13 11:47am    
<forms loginUrl="~/login.aspx" domain="MyIPAdress" timeout="2880"/>

1 solution

This was originally a comment, but I felt it was getting to long. If this doesn't help much, please let me know and I will try to provide additional information.

Could you please explain what you are trying to accomplish from the code above? The reason I ask is because it looks like you just want to extend the expiration of the cookie. The remove cookie function isn't removing the cookie since its on your machine. It updates the information in the cookie. Another complication with your method is the fact that the cookie name is the same in both the new and the old. I believe it should show as .ASPXAUTH. Using your current method you could be ending up with two authentication cookies. Then there is no guarantee of which one is being used.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900