asp.net - 如何在 http 和 https 之间共享 asp.net session

标签 asp.net ssl iis-6 https

我读到在 https 连接下运行的页面无法与在常规 http 下运行的另一个页面(或与此相同)共享一个 InProc session (基于 cookie)。我的站点在 Server 2003、IIS 6 和 .Net 2.0 上运行。

经过一些实验后,似乎在通过 https 连接时在 session 中存储数据的页面随后可以访问数据,即使在纯 http 下运行也是如此。

那么,是否有可能或者我应该检查 SSL 配置中的缺陷?

最佳答案

来自 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.

所以基本上,如果 Secure 属性设置为 false,cookie 可以通过 HTTP 和 HTTPS 传递。

我通过将此添加到我的 Global.asax 文件中避免了这个问题:

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

这意味着如果 session cookie 是通过 HTTP 创建的,那么它只能通过 HTTPS 访问。

关于asp.net - 如何在 http 和 https 之间共享 asp.net session ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/567535/

相关文章:

c# - Asp.Net 捆绑不使用 .min 文件

asp.net - MVC 升级后如何修复 Chartimg.axd

c - 根CA的SSL_CTX_set_verify()回调和深度

ASP.net HTTP 404 - 找不到文件而不是 MaxRequestLength 异常

c# - 如何设置使用 .NET Web 应用程序的子文件夹作为其基础的 IIS 网站?

asp.net - Javascript 在局部 View 中不起作用

asp.net - WCF-元数据交换配置

PHP 握手失败 TLS1.0

ssl - 具有多级子域的通配符 SSL 证书注册

c++ - WcfSvcHost 和 IIS WCF 主机遇到 BadImageFormatException