简体   繁体   English

c# ASP.NET Session 变量未初始化或更新

[英]c# ASP.NET Session Variables Not Initialising Or Updating

In my project, I'm trying to set the "userid" session variable, however for some reason the session won't initialise.在我的项目中,我试图设置“userid” session 变量,但是由于某种原因,session 不会初始化。 This behaviour is for all session variables in any controller, except my base controller, which uses a different method to set session variables. This behaviour is for all session variables in any controller, except my base controller, which uses a different method to set session variables.

Currently, I've tried these ways to set the session variable:目前,我已经尝试了这些方法来设置 session 变量:

Session.Add(...)
Session["keyname"] = "value";

I tried to initialise the session in Global.asax.cs , with some success, but these variables couldn't be updated:(我尝试在Global.asax.cs中初始化 session 并取得了一些成功,但这些变量无法更新:(

protected void Session_Start(Object sender, EventArgs e)
{            
    Session["userid"] = null;
    Session["name"] = null;
}

The normal session functionality in ASP.NET was working fine months ago, in this project, the code which uses the session variables hasn't been touched in weeks, and last worked flawlessly. ASP.NET 中的正常 session 功能几个月前工作正常,在这个项目中,使用 session 变量的代码在几周内没有被触及,并且最后一次完美无缺。

The web.config file has the current session configuration: web.config文件具有当前 session 配置:

<sessionState mode="InProc" timeout="30" />
<pages enableSessionState="true"/>

I've tried everything I've read on this forum and others, but to no avail.我已经尝试了我在这个论坛和其他论坛上阅读的所有内容,但无济于事。 I cannot regain "normal" session functionality.我无法恢复“正常” session 功能。 Please could someone provide some suggestions?请问有人可以提供一些建议吗? I'm completely lost.我完全迷路了。

Changing this:改变这个:

<httpCookies httpOnlyCookies="true" requireSSL="true" />

To this:对此:

<httpCookies httpOnlyCookies="true" requireSSL="false" />

Fix- enabling cookies over HTTP insecure connections修复启用 cookies 而非 HTTP 不安全连接

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM