(ASP.NET MVC) Create Session variable

1

I have an ASP.NET MVC application that is published on two IIS servers (approval and production);

In this application, I use the Session variable to save the user's login to a part of it, however, on the production server the creation of the Session variable is not working, returning me the error: object reference not set to an instance of an object

I think there might be some configuration in IIS because the same code works on the rationing server and also on localhost, so I can not debug.

I have never done a configuration in IIS, but when I briefly studied it, I found that there is a configuration for Session State, as shown below, but by default, it is already set to True and even changing to False, the same error continues.

Following line of code for analysis:

// POST: Auth/Login/{login}
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Login(DTOViewModel login)
{
    try
    {
        this.Autenticar(login.Usuario, login.Senha);
        Session["user"] = login.Usuario; // <---- aqui que está dando problema
        return Json(new { url = Url.Action("Index", "Usuario/Home") });
    }
    catch (Exception ex)
    {
        return Json(new { erro = ex.Message });
    }
}

Follow IIS configuration image:

Thanks to anyone who can help. :)

    
asked by anonymous 23.01.2018 / 13:34

1 answer

0

If someone has the same problem that I had, I'll document the solution:

I asked the same question in Stack Oveflow in English and it follows the link with the solution: Solution

Basically, the change that should be made to web.config

<configuration> 
    <system.webServer>
        <modules>
          <remove name="Session" />
          <add name="Session" type="System.Web.SessionState.SessionStateModule"/>
        </modules>   
    </system.webServer> 
</configuration>
    
23.01.2018 / 16:18