开发者

Update a session cookie with ASP.NET

Adding a cookie without an expiration in ASP.NET causes the cookie to expire at the end of the session. But to update the cookie is there anything special I have to do? I have seen suggestions to set the existing cookie to expire in the past, update the existing cookies expiration date, or开发者_开发技巧 simply update the value of the cookie. I tried simply updating the value of the existing cookie but this does not seem to be doing anything in Fiddler. Is there one right way to update a cookie's value in memory with ASP.NET?


You need to send a new cookie to the browser. So read the cookie from the request, change the value and add it to the response.

This sends a set-cookie header back to the client which as it has the same name overrides the one cached by the browser. next time it'll send the new cookie.

Simon


you should be allowed to update the cookies value as long as you have not ended the session (for example restarted your web broser)

make sure you don't cache your web page so that your web browser fetches a new version every time

I assume you want to update the cookies value? Also make sure that the name of your cookie is right when you try to update it.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜