c# - Session variable throw nullreference exception -


this question has answer here:

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

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -