Enabling Session State in ASP.NET MVC

旧巷老猫 提交于 2019-12-18 18:06:12

问题


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.


回答1:


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



来源:https://stackoverflow.com/questions/2620520/enabling-session-state-in-asp-net-mvc

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!