How can I remove 'no-cache=“Set-Cookie”' when I add a cookie to a HttpResponse?

前端 未结 1 710
萌比男神i
萌比男神i 2021-01-21 07:41

I\'m currently returning a cookie from a web service with code like this:

HttpResponse response = ...;
var cookie = new HttpCookie(cookieName)
{
    Value = cook         


        
1条回答
  •  一个人的身影
    2021-01-21 08:09

    HttpResponse determines whether it should add this directive based on whether the Cookies collection is non-empty. Therefore, if you add the header manually you can hide its presence from .NET:

    response.AddHeader("Set-Cookie", String.Format(
            "{0}={1}; expires={2}; path=/; secure; HttpOnly",
            cookieName, cookieValue, expiresDate.ToString("R")));
    

    0 讨论(0)
提交回复
热议问题