I am trying to set cookie which expires in 10 sec in ASP.NET MVC3 Project. But its not exipring in 10 sec. Following is my code to set cookie:
HttpCookie loginCookie = new HttpCookie(cookieName, cookieValue);
loginCookie.Expires.AddSeconds(10);
Response.Cookies.Add(loginCookie);
While I checked in chrome settings it has following status:
Expires: When the browsing session ends
Any suggestions, should i add somenthing in web.config file
Looks like you aren't actually updating the value of loginCookie.Expires - you should probably be setting the time based on the current time (DateTime.Now) and use AddSeconds like this:
See https://msdn.microsoft.com/en-us/library/system.datetime.addseconds(v=vs.110).aspx:
"This method does not change the value of this DateTime. Instead, it returns a new DateTime whose value is the result of this operation."