Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Windows Authentication in web.config in asp.net mvc4

I need to enable Windows Authentication from my web.config, without setting it in IIS.

I have the following elements in the web.config:

  authentication mode="Windows
  identity impersonate="true 

However windows authentication is not working. How do I resolve this problem ?

like image 666
zrabzdn Avatar asked May 29 '13 13:05

zrabzdn


People also ask

How do I configure Windows Authentication in web config?

On the taskbar, click Start, and then click Control Panel. In Control Panel, click Programs and Features, and then click Turn Windows Features on or off. Expand Internet Information Services, then World Wide Web Services, then Security. Select Windows Authentication, and then click OK.

How can add window authentication in ASP.NET MVC?

By default MVC apps use Form Authentication and Simple Membership, so you need to make it "false" to run Windows Authentication. Select the project name in Solution Explorer and then in the Property Explorer, click to enable Windows Authentication.

How do I turn off Windows Authentication in web config?

In the IIS Manager: Expand the computer name, then Sites, then Default Web Site, then click on the name of the desired site. Select Authentication. Set Windows Authentication to Disabled and set Basic Authentication to Enabled.


3 Answers

For IIS Express

You can set it up here. You may also wish to disable anonymous access

Setting Windows auth for IIS Express

For IIS

I found it was necessary to set this under system.webServer

<system.webServer>
    […]
    <security>
      <authentication>
        <anonymousAuthentication enabled="false"/>
        <windowsAuthentication enabled="true"/>
      </authentication>
    </security>
  </system.webServer>

This does almost the same thing as the @Dimitar suggestion - use IIS Manager to change the setting. The difference is that the config file avoids a manual step - but adds this next one:

Note:

By default, IIS Feature Delegation locks some of those settings (Basic & Windows auth), so you'll need to go to the root of the IIS server, and enable those to be read/write. E.g.:

Feature delegation - Allowing read/write for auth section

A more detailed description of accessing Feature Delegation is here.

like image 71
Overflew Avatar answered Oct 19 '22 02:10

Overflew


If by this you mean running your project from Visual Studio (IISExpress - not IIS), then you can try to do the following:

In Visual Studio -> Click on the root of your project -> Press F4 in order to open the properties pane -> Look for "Windows Authentication" and mark is as "Enabled" -> Run your project.

like image 8
Dimitar Dimitrov Avatar answered Oct 19 '22 02:10

Dimitar Dimitrov


Unfortunately you must use IIS to enable Windows authentication. You cannot do it in Web.config alone. (At least up to IIS 8.5, the current version as of this post.)

This is because the Web.config elements for enabling Windows authentication (<system.webServer><security><authentication><windowsAuthentication>) can only be defined in applicationHost.config (C:\Windows\System32\inetsrv\config).

like image 5
Keith Avatar answered Oct 19 '22 03:10

Keith