在 ASP.NET MVC 中启用会话状态
我想在 ASP.NET MVC 应用程序中使用会话变量。
我已经在我的 web.config
文件中添加了
标记,
<sessionState mode="InProc" cookieless="false" timeout="20">
</sessionState>
如果我使用 cookieless=",我会在我的 url 中得到一个会话 ID,如下所示true"
http://localhost:2967/%28S%28hcawmi55zoruuy453fbo3k55%29%29/RmdReqBankAccount
但我仍然无法在我的应用程序中使用会话变量。
我在登录方法中设置了这样的变量:
Session["username"] = userName;
并且像这样检索它,
string user_id = (string)Session["username"];
在尝试检索值时得到一个空字符串。
I'd like to use session variables in my ASP.NET MVC application.
I already added the <sessionState>
tag in my web.config
file like this
<sessionState mode="InProc" cookieless="false" timeout="20">
</sessionState>
I get a session ID in my url like this if I use cookieless="true"
http://localhost:2967/%28S%28hcawmi55zoruuy453fbo3k55%29%29/RmdReqBankAccount
But I still can't use session variables in my application.
I set the variable like this in my login method:
Session["username"] = userName;
and I retrieve it like this
string user_id = (string)Session["username"];
I get an empty string when trying to retrieve values.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
已修复,在编写设置的会话变量时,我似乎得到了错误的位置。
Fixed , it seems I got the wrong location when writing the set session variables.