开发者

Windows authentication in MVC 3

开发者 https://www.devze.com 2023-04-01 20:19 出处:网络
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

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:

  1. Enable basic authentication in IIS. (I have also tried to enable Windows Authentication)
  2. Web.config <authentication mode="Windows"></authentication>
  3. I have tried with and without <identity impersonate="true"/>
  4. I have put the AuthorizeAttribute within my controllers.
  5. I have tried also the <add key="autoFormsAuthentication" value="false"/> fix for MVC3 Beta.

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 use开发者_StackOverflowr 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.


I had the same problem, it got resolved after I added the following tag in my <appSettings> in my root web.config.

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

along with this

<add key="autoFormsAuthentication" value="false"/>
0

精彩评论

暂无评论...
验证码 换一张
取 消