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:05 AM UTC

Closing this forum since its duplicate of https://www.syncfusion.com/forums/177756/get-windows-network-user-name


Loader.
Up arrow icon