0

How can I get the DOMAIN/username in MVC Core once published? I have Identity installed, and realize that for logged-in users

HttpContext.User.Identity.Name

would work but prefer that all users do not need to be logged in. Rather, I would like to use the client box domain/username.

In a local environment, I can do this with:

System.Security.Principal.WindowsIdentity.GetCurrent().Name;

but this doesn't work once published. Once published it renders "IIS APPPOOL/AppName". Is this the expected functionality? If not, how do I fix this?

Most of the information I can find online relates to modifying the web.config file...

The closest I could find is Windows Authentication with asp.net core

but I'm not sure how I would implement in the controller once I follow that

coolhand
  • 1,876
  • 5
  • 25
  • 46
  • " I would like to use the box domain/username." Which box, the user's or the server's? You also don't need Identity for Windows authentication – Camilo Terevinto Oct 07 '17 at 22:48
  • the user's (client) machine. And yes, I realize I don't need Identity for this function, but I use it for other functions within the application – coolhand Oct 07 '17 at 22:52
  • 1
    `HttpContext.User.Identity.Name` will give you the user's `DOMAIN\username` name when logged-in through Windows Authentication. It's not possible to get it without the user being logged-in, but, if you disable Anonymous Authentication, it *should be* automatic (though this would break Identity) – Camilo Terevinto Oct 07 '17 at 22:54
  • So adding this functionality and using Identity are mutually exclusive? – coolhand Oct 07 '17 at 23:03
  • If you want auto-authenticate through Windows, I think so. Never really tried, though. For Identity to work you'd need `Anonymous Authentication` enabled, so `Windows Authentication` would not be automatic – Camilo Terevinto Oct 07 '17 at 23:06
  • are u hosting directly on iis or on some online hosting service? – Neville Nazerane Oct 08 '17 at 00:39
  • I'm hosting on Azure – coolhand Oct 08 '17 at 02:27

1 Answers1

0

After a decent amount of searching, it looks like it isn't easily feasible as Camilo Terevinto stated. I'm going to have to implement Identity for all users.

coolhand
  • 1,876
  • 5
  • 25
  • 46