Hi,
I am trying to get Windows network user name (Ad Name) (Blazor Server).
I used the following code:
@page "/"
@using Microsoft.AspNetCore.Http
@inject IHttpContextAccessor httpContextAccessor
Index
@UserName
@code{
public string UserName;
protected override void OnInitialized()
{
try
{
UserName = httpContextAccessor.HttpContext.User.Identity.Name.ToString();
}
catch (Exception e)
{
UserName = "This error message" + e.ToString();
}
}
}
It works fine under Dev server. Once I move the code to Production server. I got an error message that System.NullReferenceException: Object reference not set to an instance of an object. at on
chrome, Fireforx and Edge browesers. However, I got the user name under IE browser.