I have this application I need to get the name of the windows logged user. I hosted this on a server. When I am tested locally this works perfectly but when I hosted on the server the program returns the server name, not the logged user username. My code is mentioned below
Index.cshtml
<h1>Hello @ViewBag.UserName</h1>
Controller
public ActionResult Index()
{
string name = System.Security.Principal.WindowsIdentity.GetCurrent().Name;
string x = "";
x = name.Split('\\')[1];
ViewBag.UserName = x;
return View();
}
Web.config
<system.web>
<compilation debug="true" targetFramework="4.8" />
<httpRuntime targetFramework="4.8" />
<authentication mode="Windows"/>
</system.web>
Any help is appreciated. Thank you.