zrabzdn
zrabzdn

Reputation: 1435

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 ?

Upvotes: 10

Views: 44653

Answers (4)

Overflew
Overflew

Reputation: 8182

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.

Upvotes: 16

Keith
Keith

Reputation: 21264

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).

Upvotes: 6

Dimitar Dimitrov
Dimitar Dimitrov

Reputation: 15158

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.

Upvotes: 8

Piotr Stapp
Piotr Stapp

Reputation: 19828

If windows authentication is not installed on IIS it won't work. If it is installed setting in web.config should be fine

Upvotes: 2

Related Questions