Enabling Session State in ASP.NET MVC

Posted by Erwin on Stack Overflow See other posts from Stack Overflow or by Erwin
Published on 2010-04-12T07:37:59Z Indexed on 2010/04/12 16:02 UTC
Read the original article Hit count: 646

Filed under:
|
|
|

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.

© Stack Overflow or respective owner

Related posts about asp.net-mvc

Related posts about session-state