在 ASP.NET MVC 中启用会话状态

发布于 2024-08-28 21:41:19 字数 650 浏览 1 评论 0原文

我想在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

落花随流水 2024-09-04 21:41:19

已修复,在编写设置的会话变量时,我似乎得到了错误的位置。

Fixed , it seems I got the wrong location when writing the set session variables.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文