在ASP.NET MVC中启用会话状态 [英] Enabling Session State in ASP.NET MVC
本文介绍了在ASP.NET MVC中启用会话状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在我的ASP.NET MVC应用程序中使用会话变量。
I'd like to use session variables in my ASP.NET MVC application.
我已经添加了<的sessionState>
的标签我的web.config
文件中像这样
I already added the <sessionState>
tag in my web.config
file like this
<sessionState mode="InProc" cookieless="false" timeout="20">
</sessionState>
我在我的网址是这样获得的会话ID,如果我用无cookie =真正的
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;
和我找回它像这样
string user_id = (string)Session["username"];
我得到试图检索值时,一个空字符串。
I get an empty string when trying to retrieve values.
推荐答案
固定,看来我写了一组会话变量时,错误的位置。
Fixed , it seems I got the wrong location when writing the set session variables.
这篇关于在ASP.NET MVC中启用会话状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文