I have 2 projects in the solution, a console app and the MVC project. The console app will fire a request to http://localhost:68220/MyMvcArea/MyMvcController/MyMvcMethod
. The MyMvcMethod
is decorated with [Authorized]
attribute in the MVC controller.
Debugging was OK in Visual Studio 2010 and 2012 with the development server using Windows Authentication mode. Now I'm trying out Visual Studio 2013 with the same solution, I'm getting a 401 - Unauthorized response.
I enabled Windows Authentication for my MVC project in both the global applicationhost.config file and in the project properties, I can access to the method in a browser, but the console app still gets a 401 response. The console app is also running under my Windows account as I can verify it in the Task Manager.
Does anyone know how to get around with this? I only need this to work for the debugging IIS Express in Visual Studio.
Edit:
I've checked the IIS Express log, the sub-status code is 2. So according to MSDN, 401.2 refers to "Logon failed due to server configuration".
I found a work around to this problem. When creating the web request in windows service, I need to explicitly set the credential:
request.Credentials = CredentialCache.DefaultNetworkCredentials;
However, we never needed to do this in VS2012, this looks a bit like a bug to me in the new version of IIS Express now.
Edit: The above line is needed before each request is sent to the server, for example:
var request = (HttpWebRequest)WebRequest.Create(url);
request.Credentials = CredentialCache.DefaultNetworkCredentials;
request.BeginGetResponse(AsyncResponseCallback, state);