Reputation: 11759
I would like to know if there is a way to write and read cookies from a generic handler.
For now, when I check the cookies in the browser developer tools, they are null.
Here is my code:
public void ProcessRequest(HttpContext context)
{
CreateCookie(Username,SessionID);
}
public void CreateCookie(string userName, string sessionID)
{
HttpContext.Current.Response.Cookies["SESSION"]["SESSIONID"] = Encryption.EncryptString(sessionID);
HttpContext.Current.Response.Cookies["USER"]["USERNAME"] = Encryption.EncryptString(userName);
}
I cannot replace my cookies by SessionState element as the code can be executed on a server farm, messing up with the session.
Any idea?
Thanks!
Upvotes: 2
Views: 2299
Reputation: 3508
Does the handler implement IReadOnlySessionState and IRequiresSessionState interfaces to access and manipulate session variables.
http://msdn.microsoft.com/en-us/library/system.web.sessionstate.ireadonlysessionstate.aspx
http://msdn.microsoft.com/en-us/library/system.web.sessionstate.irequiressessionstate.aspx
Upvotes: 3