My .Net Core MVC application runs on VS2017, IIS Express well.
Once I publish and deploy it to IIS in my local computer, I get the following error message
This page isn’t working
localhost is currently unable to handle this request.
HTTP ERROR 500
Once I remove the line below on the Header.cshtml file, It runs without any issue.
@inject IHttpContextAccessor HttpContextAccessor
The following lines are in the _Layout.cshtml file
<body>
@Html.Partial("Header")
@RenderBody()
@Html.Partial("Footer")
</body>
The reason I need @inject IHttpContextAccessor HttpContextAccessor is for getting session value from controller, see lines in Header.cshtml file below
@using Microsoft.AspNetCore.Http;
@inject IHttpContextAccessor HttpContextAccessor
@{
string UserFullName = HttpContextAccessor.HttpContext.Session.GetString("UserFullName");
string UserSecurityGroup = HttpContextAccessor.HttpContext.Session.GetString("UserSecurityGroup");
string LastLoginDate = HttpContextAccessor.HttpContext.Session.GetString("LastLoginDate");
}
In the HomeController, I set these session values by using the following lines
HttpContext.Session.SetString("UserFullName", user.LastName + ", " + user.FirstName);
HttpContext.Session.SetString("UserSecurityGroup", user.IsSystemAdmin == true ? "Admin" : "User");
HttpContext.Session.SetString("LastLoginDate", DateTime.Now.ToString("MM/dd/yyyy"));
Is there any other ways, I can get these session value in cshtml file? Thanks.