I’m trying to set up Windows authentication in my web app, but I cannot make it work. The app run in my computer (Windows 7 x64), I am in a domain network, and the app is running on the real IIS, not the Cassini web server.
What I have done so far:
- Enable basic authentication in IIS. (I have also tried to enable Windows Authentication)
- Web.config
<authentication mode="Windows"></authentication> - I have tried with and without
<identity impersonate="true"/> - I have put the
AuthorizeAttributewithin my controllers. - I have tried also the
<add key="autoFormsAuthentication"fix for MVC3 Beta.
value="false"/>
What I got:
I can open the page that has no AuthorizeAttribute, I put a breakpoint and this is what I get in different properties related with authentication:
System.Security.Principal.WindowsIdentity.GetCurrent().Name
"IIS APPPOOL\\ASP.NET v4.0 DefaultAppPool"
Environment.UserDomainName
"IIS APPPOOL"
Environment.UserName
"ASP.NET v4.0 DefaultAppPool"
User.Identity.Name
""
Of course I cannot open any page with the [Authorize] attribute.
The only thing I want is get the Windows user name of the user that is accessing the web application. How should I do it?
It worked after reboot the computer. No idea what was wrong.