0

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.

rahularyansharma
  • 11,156
  • 18
  • 79
  • 135
Catalin
  • 11,503
  • 19
  • 74
  • 147

1 Answers1

1

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.

Dai
  • 141,631
  • 28
  • 261
  • 374
  • surprised why he posted that question because i got the link on first place in google with these keywords 'How to create non persistent cookies' – rahularyansharma Apr 11 '13 at 09:29
  • I was looking for "non persistent cookies in asp.net mvc" because i thought it required a special implementation from asp.net – Catalin Apr 12 '13 at 06:11