How can i create a cookie in Asp.net MVC that should be valid only for the current browser tab?
When the user closes or changes the tab, the cookie should be deleted.
How can i create a cookie in Asp.net MVC that should be valid only for the current browser tab?
When the user closes or changes the tab, the cookie should be deleted.
From the QA that rahularyansharma linked to, like so:
HttpCookie cookie = new HttpCookie("myCookieName", "myCookieValue");
Response.Cookies.Add(cookie);
The above code creates a cookie with no expiration value set, so the client browser will not store it, so it will be deleted when the browser session ends, this is typically when the window or tab is closed.
None of this code is MVC-specific.