get Windows network user name

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.


1 Reply

SR Sivakumar R Syncfusion Team September 29, 2022 06:04 AM UTC

Hi Ali,


Your query is not related to Syncfusion components. Also, we haven't experimented this particular use on our side. So, requesting to check this query in stack overflow.

 

Thanks,

Sivakumar 


Loader.
Up arrow icon