Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

the rest of the application works as intended by using the Authorize attribute the actions i need secured.

I just need to say to the app "get the current machine logged in user , dont secure anything and take the user to the landing page".

web.config:

<authentication mode="Windows" />

like this the user is BLANK on the landing page.

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

Is there any way around this?

UPDATE:

No matter what you do , it seems that there is no way to bypass the login prompt and make the application automatically get the current domain user and log him in the app.

like image 812
e4rthdog Avatar asked Oct 08 '13 08:10

e4rthdog


1 Answers

Check this from MSDN

add impersonate="true" along with it

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

Then use

 ((HttpContext)context).User.Identity as WindowsIdentity
like image 59
Murali Murugesan Avatar answered Nov 15 '22 11:11

Murali Murugesan