c# - Session variable throw nullreference exception -
this question has answer here:
- what nullreferenceexception, , how fix it? 29 answers
i have web application using asp mvc4
i set session variable in
protected void session_start() { session["__userlanguage"] = "en"; }
and use on controller
private void addtranslation() { string language = request.form["language"]; if (language != null) { session["__userlanguage"] = language; } else { language = session["__userlanguage"] string; } }
but when publish on iis return
system.nullreferenceexception: object reference not set instance of object.
when try in controller
session["__userlanguage"] = language;
why ? :'(
edit : in fact after debugging session_start() not used in application ... how that's possible ?
edit 2 : after adding
<remove name="session" /> <add name="session" type="system.web.sessionstate.sessionstatemodule" precondition="" />
this resolve problem ! why that's not directly added visual studio :(
after adding
<remove name="session" /> <add name="session" type="system.web.sessionstate.sessionstatemodule" precondition="" />
this resolve problem!
Comments
Post a Comment