I have a web application using ASP MVC4
I set my session variable in
protected void Session_Start()
{
Session["__UserLanguage"] = "EN";
}
And I use it on my controller
private void AddTranslation()
{
string language = Request.Form["Language"];
if (language != null)
{
Session["__UserLanguage"] = language;
}
else
{
language = Session["__UserLanguage"] as string;
}
}
but when i publish it on IIS it return
System.NullReferenceException: Object reference not set to an instance of an object.
when I try to get it in my controller
Session["__UserLanguage"] = language;
Why ? :'(
EDIT : In fact After debugging Session_Start() was not used in my application ... How that's possible ?
EDIT 2 : after adding
<remove name="Session" />
<add name="Session" type="System.Web.SessionState.SessionStateModule" preCondition="" />
This resolve my problem ! Why that's not directly added by visual studio :(