Warm tip: This article is reproduced from stackoverflow.com, please click
.net asp.net asp.net-mvc cookies webforms

Asp.net life cycle event to change Response.Cookies

发布于 2020-04-10 10:07:12

In Asp.Net, is there any life cycle event from where I can modify the Response Cookies ?

I want a common place where I can set the SameSite flag on all cookies added by any code. I also need an access to HttpContext.Current.Session in that event.

I already tried PreSendRequestHeaders, PostReleaseRequestState, PostAcquireRequestState and EndRequest but none of them worked.

Questioner
Jay Shah
Viewed
52
Jay Shah 2020-02-01 07:28

It cannot be achieved in one event.

So I used PreSendRequestHeaders to change the response.cookies.
It doesn't have access to Session object, but I added required session variables in Request.Cookies in Session_Start event.
Note: Adding something in Request.Cookies doesn't make any change in response cookies.