Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Authentication issue when debugging in VS2013 - iis express

I'm trying to pick up the windows username when debugging in Visual Studio 2013. I am simply using:

httpcontext.current.user.identity.name 

If I run this on my Dev Server it works fine, if I run it in debug mode on any previous version of Visual Studio it also works fine.

My problems is - If i run this on visual studio 2013 I get an empty string.

My web config is as follows.

<system.web>     <authentication mode="Windows"/>     <identity impersonate="false"/>     <authorization>        <allow users="*"/>     </authorization>     <compilation debug="true" strict="false" explicit="true" targetFramework="4.0"/>     <customErrors mode="Off"/> </system.web> 
like image 684
Neil Watson Avatar asked Oct 22 '13 10:10

Neil Watson


People also ask

How do I enable basic authentication in IIS Express?

On the Server Roles page, expand Web Server (IIS), expand Web Server, expand Security, and then select Basic Authentication. Click Next. On the Select features page, click Next. On the Confirm installation selections page, click Install.

Could not start debugging on the web server?

Open your project properties and make sure that the project is configured to connect to the correct Web server and launch URL. (Open Properties > Web > Servers or Properties > Debug depending on your project type.) If that does not work or you are debugging remotely, follow steps in Check your IIS Configuration.

How do I change Windows Authentication in Visual Studio?

For . Start Visual Studio and select Create a new project. In the Create a new project dialog, select ASP.NET Core Web App (or Web API) > Next. In the Configure your new project dialog, enter Project name > Next. In the Additional Information dialog, select Authentication Type as Windows.


2 Answers

I had just upgraded to VS 2013 from VS 2012 and the current user identity (HttpContext.User.Identity) was coming through as anonymous.

I tried changing the IIS express applicationhost.config, no difference.

The solution was to look at the properties of the web project, hit F4 to get the project properties when you have the top level of the project selected. Do not right click on the project and select properties, this is something entirely different.

Change Anonymous Authentication to be Disabled and Windows Authentication to be Enabled.

Works like gravy :)

like image 100
Toby Simmerling Avatar answered Oct 07 '22 01:10

Toby Simmerling


As I was researching this I found my answer, but can't find the answer on the internet, so I thought I'd share this:

I fixed my issue by modifying my applicationhost.config file. My file was saved in the "\My Documents\IISExpress\config" folder.

It seems that VS2013 was ignoring my web.config file and applying different authentication methods.

I had to modify this portion of the file to look like the below. In truth, I only modified the anonymousAuthentication to be false and the windowsAuthentication mode to true.

<authentication>    <anonymousAuthentication enabled="false" userName="" />    <basicAuthentication enabled="false" />    <clientCertificateMappingAuthentication enabled="false" />    <digestAuthentication enabled="false" />    <iisClientCertificateMappingAuthentication enabled="false">   </iisClientCertificateMappingAuthentication>    <windowsAuthentication enabled="true">     <providers>       <add value="Negotiate" />       <add value="NTLM" />     </providers>   </windowsAuthentication>  </authentication> 
like image 44
Neil Watson Avatar answered Oct 07 '22 01:10

Neil Watson