Windows authentication doesn't work when I run project from Visual Studio
Asked Answered
I

3

23

Windows authentication works good when I host my ASP.NET MVC project on IIS. But if I run it from Visual Studio - it doesn't.

Here is my Web.config:

<authentication mode="Windows" />
<authorization>
  <deny users="?" />
</authorization>

Am I missing something?

Inherited answered 11/6, 2013 at 11:37 Comment(2)
what OS? what version of MVC? what version of visual studio? is visual studio running as administrator?Soane
Windows 7, MVC 4, Visual Studio is running as administratorInherited
V
53

If you are hosting in IIS Express (which you probably should), make sure you have enabled Windows Authentication in the properties of your Web Application.

By the way if you create a new ASP.NET MVC 4 application in Visual Studio using the Intranet Application template you will be greeted with the following Readme on the screen. So go ahead, try it, read it and follow what's written there:

To use this template with Windows Azure authentication, refer to http://go.microsoft.com/fwlink/?LinkID=267940.

Otherwise, to use this template with Windows authentication, refer to the instructions below:

Hosting on IIS Express:

  1. Click on your project in the Solution Explorer to select the project.
  2. If the Properties pane is not open, open it (F4).
  3. In the Properties pane for your project:
    a) Set "Anonymous Authentication" to "Disabled".
    b) Set "Windows Authentication" to "Enabled".

Hosting on IIS 7 or later:

  1. Open IIS Manager and navigate to your website.
  2. In Features View, double-click Authentication.
  3. On the Authentication page, select Windows authentication. If Windows authentication is not an option, you'll need to make sure Windows authentication is installed on the server.

To enable Windows authentication on Windows:

a) In Control Panel open "Programs and Features". b) Select "Turn Windows features on or off". c) Navigate to Internet Information Services > World Wide Web Services > Security and make sure the Windows authentication node is checked.

To enable Windows authentication on Windows Server:

a) In Server Manager, select Web Server (IIS) and click Add Role Services. b) Navigate to Web Server > Security and make sure the Windows authentication node is checked.

  1. In the Actions pane, click Enable to use Windows authentication.
  2. On the Authentication page, select Anonymous authentication.
  3. In the Actions pane, click Disable to disable anonymous authentication.
Vinaya answered 11/6, 2013 at 13:26 Comment(3)
I have not found auth settings for iis express, I decided to host my project on IIS 7 and configured project appropriately. Thanks for the answer!Inherited
It's been a few years since you wrote this, but the readme is definitely helpful. It doesn't appear - at least not the same one - with some other (3rd party) project templates. Thanks for posting it.Treasurer
A little late, but to get to those local IIS Express settings, click once on your project node beneath the SLN node in the solution explorer, then press the F4 key. It's in the Project Properties pane, not the My Project pane, if that makes sense.Echovirus
H
7

I couldn't quite get the @Darin Dimitrov solution to work (mainly as I couldn't find the IIS Express setting described in Visual Studio!).

I found I had to edit the IIS Express application.config file:

  • in Visual Studio 2013 this is in %userprofile%\documents\iisexpress\config
  • in Visual Studio 2015 this is in the config folder in the hidden .vs folder in the solution (just add \.vs\config in Windows explorer to get there).

and amend:

<windowsAuthentication enabled="false">

to:

<windowsAuthentication enabled="true">
Hymn answered 28/3, 2018 at 8:54 Comment(0)
I
1

I know this is late to the game on this question but for Visual Studio 2019 it changed slightly. So if you find yourself sorting through this for that solution in debugger:

From : Microsoft Documentation

And taken from that page, which did work for me: Existing project

The project's properties enable Windows Authentication and disable Anonymous Authentication:

Right-click the project in Solution Explorer and select Properties.

Select the Debug tab.

Clear the checkbox for Enable Anonymous Authentication.

Select the checkbox for Enable Windows Authentication.

Save and close the property page.

Intermolecular answered 26/5, 2021 at 18:24 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.