I have an ASP.NET MVC application which retrieves current logged in user id (Windows login id).
It works in Visual Studio, running with localhost. But after publishing, this value is returned as empty.
var windowsLogin = User?.Identity?.Name ?? HttpContext?.User?.Identity?.Name ?? string.Empty; //This will return domain\userid, in VisualStudio,localhost; empty in published url
string currentUser = WindowsIdentity.GetCurrent()?.Name; //empty in published url
I've tried these steps:
- Windows authentication enabled in webconfig and IIS.
- Anonymous authentication disabled in both.
- AppPool identity is being used in IIS as identity.
I have tried to publish it with localhost, then userid is showing.
But using a hostname (DNS), user id is empty.
What is wrong here?
(Get-CimInstance Win32_ComputerSystem).Domainshould return the name of the domain $\endgroup$