I want to get current windows user name when user opens the website. My application uses Blazor server-side. To get current username, I added:
- In startup.cs:
services.AddHttpContextAccessor();
(under ConfigureServices) - In razor page:
@inject IHttpContextAccessor httpContextAccessor
- In razor page method:
string userName = httpContextAccessor.HttpContext.User.Identity.Name;
When I execute the code, the application throws an exception:
"An error has occurred. This application may no longer respond until reloaded."
I get this error only when I deploy on IIS. On local machine it works well.