1
I have an ASP.NET MVC application that is published on two IIS servers (homologation and production);
In this application, I use the Session variable to save the user’s login in a part of it, however, in the production server is not working the creation of the Session variable, returning me the error: object reference not set to an instance of an object
I believe it may be some configuration on IIS because the same code works on the homologation server and also on localhost, so I can’t debug.
I never made configuration in IIS, but while studying briefly about it, I found that there is a configuration for Session State, as shown below, however, by default, it is already set to True and even changing to False, still the same error.
Follow code line 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 those who can help. :)
It seems to me a common balancing behavior, you may be creating the session on one server and the next request is answered by the other, where this session was not created.
– Leandro Angelo
I’m not sure I understand your reply @Leandroangelo, could you enlighten me? From what I understand the session variable may not have been created at this time of the application, but what confuses me is the homologation server works normally.
– Guilherme Golfetto
Forget it, I read the beginning of your question wrong.
– Leandro Angelo