ASP.NET MVC intranet application with Windows authentication, how to get the current domain user automatically?

I need my MVC4 application to get the current domain user who is logged in on a machine that is automatically registered on my index.cshtml page.

the rest of the application works as intended, using the Authorize attribute, the security measures I need.

I just need to tell the application "get the current machine registered by the user, do not protect anything and do not deliver the user to the landing page."

web.config:

<authentication mode="Windows" /> 

like this, the user on the BLANK destination page.

If I try to put only [Authorize] on my action by index, then it asks for credentials, and then continues, as I want, without anything on the landing page.

Is there any way around this?

UPDATE:

No matter what you do, there seems to be no way to get around the login prompt and force the application to automatically get the current domain user and register it in the application.

+6
source share
4 answers

Refuse MSDN

add impersonate="true" with it

  <identity impersonate="true"/> <authentication mode="Windows" /> 

Then use

  ((HttpContext)context).User.Identity as WindowsIdentity 
+3
source

Use Windows Authentication for both ASP.NET and IIS and specify ASP.NET URL authorization in web.config as shown in this answer . Whenever the current user is logged in, the user will be quietly registered.

Tested using IE 11, IIS 8.5, Windows Server 2012 R2.

+1
source

I just finished fighting this problem. I have to preface that this is with iis 7 running on win 2k8r2. the fix for me was to go to the authentication menu in iis -> select windows authentication -> click providers in the right pane -> configure so that only ntlm was in the list of available providers. appears to be the culprit in forcing a login request.

+1
source

You can also try adding the following to your <appSettings> :

 <add key="enableSimpleMembership" value="false" /> 
0
source

Source: https://habr.com/ru/post/955471/


All Articles