ASP.NET_SessionId + OWIN Cookies do not send to browser

后端 未结 9 1419
误落风尘
误落风尘 2020-11-22 14:00

I have a strange problem with using Owin cookie authentication.

When I start my IIS server authentication works perfectly fine on IE/Firefox and Chrome.

I st

9条回答
  •  青春惊慌失措
    2020-11-22 14:36

    If you are setting cookies in OWIN middleware yourself, then using OnSendingHeaders seems to get round the problem.

    For example, using the code below owinResponseCookie2 will be set, even though owinResponseCookie1 is not:

    private void SetCookies()
    {
        var owinContext = HttpContext.GetOwinContext();
        var owinResponse = owinContext.Response;
    
        owinResponse.Cookies.Append("owinResponseCookie1", "value1");
    
        owinResponse.OnSendingHeaders(state =>
        {
            owinResponse.Cookies.Append("owinResponseCookie2", "value2");
        },
        null);
    
        var httpResponse = HttpContext.Response;
        httpResponse.Cookies.Remove("httpResponseCookie1");
    }
    

提交回复
热议问题