Click here to Skip to main content
15,900,258 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello All,

I have one overlay div inside a condition.

If Cookies[“User”] is null then I show overlay div having two radio buttong and one submit button.
When user select radio option and click submit button,when by ajax call ,I am calling an action ,
Which sets cookies.

I have putted Overlay div inside layout page,so for every call it checkes for session.

My issue is : First time after setting cooikes, it’s not persist for second time.
Below is my method which sets cookies:

public ActionResult SaveUserTypeCookies(string usertype, string returnUrl)
{
if (Request.Cookies["User"] != null)
{
HttpCookie cookie = Request.Cookies["User"];
cookie.Values["UserType"] = usertype;
cookie.Expires = DateTime.MaxValue;
Response.SetCookie(cookie);
}
else
{
HttpCookie cookie = new HttpCookie("User");
cookie.Values["UserType"] = usertype;
cookie.Expires = DateTime.MaxValue;
Response.Cookies.Add(cookie);


}
return Redirect(returnUrl);


Below is my contion for overlay div:

@if ((Request.Cookies["User"]== null))
{


}
Posted

Below links will help you:
http://www.chwe.at/2009/01/don-t-use-response.cookies-string--to-check-if-a-cookie-exists/[^]

Sometime DateTime.MaxValue can also cause trouble as described in below link:
http://stackoverflow.com/questions/6127123/net-datetime-maxvalue-is-different-once-it-is-stored-in-database[^]

So there may be precision issue with C# and JavaScript, so try something like
DateTime.Now.AddHours(12);

and check whether they are setting at client side or not.

Try those and share if you can get success. Thanks.
 
Share this answer
 
v2
Thank you for you response,but it doesn't help,still issue is there :(
 
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