set cookie to expire at end of session? asp.net

前端 未结 4 1535
无人及你
无人及你 2020-12-01 14:01

I\'m surprised I couldn\'t find any answers.

How do I set my sessionid in my cookie to expire at the end of session? (when the browser closes or the user has been in

4条回答
  •  执念已碎
    2020-12-01 14:19

    TimeOut returns an int, Expires expects DateTime, which is why that code will not compile. Setting the expiration date to date in the past immediately revokes the cookie, so that's probably not what you want. If you left the expiration date unused, the cookie would expire as soon as the user closed the browser.

    If you want the cookie tied to the particular Session, why involve the cookie in the first place? You could certainly keep extending the cookie's expiration date each time the user extended the session by using your application, but that seems like unnecessary work. Just use Session.

    Feel free to elaborate on the problem.

提交回复
热议问题