Your usage of Response.Redirect is totally wrong, since .cshtml files are not accessed directly like webforms pages (.aspx) have (they need to be returned as view by controller action method). If you're working in MVC controller, use RedirectToAction instead.
if (Session["IdUsuario"] == null)
{
return RedirectToAction("Index", "Home"); // replacement of Response.Redirect to root page
}
else
{
if ((bool)Session["Temporal"] == true)
{
// use RedirectToAction instead of Response.Redirect
return RedirectToAction("ContrasenaTemporal", "Login");
}
else
{
// return something else
}
}
Also the target action method should be like this:
// inside LoginController class
public ActionResult ContrasenaTemporal()
{
// other stuff
return View("ContraseñaTemporal");
}
Edit 1:
In case you want to redirect from a view page, you still need to follow virtual path in MVC with usage of Response.Redirect, pointing to given controller action method above:
@if (Session["IdUsuario"] == null)
{
Response.Redirect("~/Home/Index");
}
else
{
if ((bool)Session["Temporal"] == true)
{
Response.Redirect("~/Login/ContrasenaTemporal"); // follow MVC route convention
}
}