Quantcast
Channel: Active questions tagged blazor - Stack Overflow
Viewing all articles
Browse latest Browse all 4839

Blazor throwing error when using HttpContext

$
0
0

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:

  1. In startup.cs:
    services.AddHttpContextAccessor(); (underConfigureServices)
  2. In razor page:
    @inject IHttpContextAccessor httpContextAccessor
  3. 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.


Viewing all articles
Browse latest Browse all 4839

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>