how can I share an asp.net session between http and https

感情迁移 提交于 2019-11-27 01:46:48
John Rasch

From MSDN:

When a user moves back and forth between secure and public areas, the ASP.NET-generated session cookie (or URL if you have enabled cookie-less session state) moves with them in plaintext, but the authentication cookie is never passed over unencrypted HTTP connections as long as the Secure cookie property is set.

So basically, the cookie can be passed over both HTTP and HTTPS if the Secure property is set to false.

I have avoided this issue by adding this to my Global.asax file:

void Session_Start(object sender, EventArgs e) 
{
    if (Request.IsSecureConnection) Response.Cookies["ASP.NET_SessionID"].Secure = false;
}

This means that if the Session cookie is created over HTTP, it will only be accessible over HTTPS.

IIS setting In the IIS properties window, under the ASP tab –> Session Properties, there is a setting for “New ID on Secure Connections”

I fixed this intermittent issue for myself by setting this to false.

Searching for the problem doesn't turn up much chatter about it so far, still looking.

Edit: okay finding some stuff now.

Right it seems that it will work fine if both sets of pages are in the same application/website.

So I'd go ahead and carry on, feeling reassured.

If any of the above solution does not work try this. I have cracked this out after doing research of a couple of days.

app.UseCookieAuthentication(new CookieAuthenticationOptions
{
    ...
    ...
    CookieSecure = CookieSecureOption.Never
});
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!