0
$\begingroup$

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?

$\endgroup$
3
  • $\begingroup$ Are you sure Anonymous and all other authentication types are disabled? Is the published server actually joined to the AD domain? $\endgroup$ Commented Jan 12 at 11:58
  • $\begingroup$ Yes. Only windows authentication enabled. How to check if server joined AD. The code developed and published in same server IIS. There is a DNS created. If hostname is removed, all working fine. but need hostname. $\endgroup$ Commented Jan 12 at 19:09
  • $\begingroup$ Powershell (Get-CimInstance Win32_ComputerSystem).Domain should return the name of the domain $\endgroup$ Commented Jan 12 at 19:23

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.