Hi all,
I need to get the end user windows Id to do a query on a database in a MVC 6 application.
For this, I've set the authentication mode = windows and impersonate = true in my web.config as shown below. As the MVC6 app pool runs on No Managed Code I also added validateIntegratedModeConfiguration = false.
<?xml version="1.0" encoding="utf-8"?><configuration><system.webServer><validation validateIntegratedModeConfiguration="false" /><handlers><add name="httpPlatformHandler" path="*" verb="*" modules="httpPlatformHandler" resourceType="Unspecified" /></handlers><httpPlatform processPath="%DNX_PATH%" arguments="%DNX_ARGS%" stdoutLogEnabled="false" startupTimeLimit="3600" forwardWindowsAuthToken="true" /></system.webServer><system.web><authentication mode="Windows" /><identity impersonate="true"/></system.web></configuration>
In a controller context, User.Identity always comes as null, and both System.Security.Principal.WindowsIdentity.GetCurrent().Name and System.Environment.UserName get me the user that's running the AppPool in the server and not the windows end-user.
I'm running out of ideas... This was so trivial in previous versions of MVC and now is such a pain!
Any help would be much appreciated.
Thanks!