我在解决方案中有2个项目,一个控制台应用程序和MVC项目。 控制台应用程序将向http://localhost:68220/MyMvcArea/MyMvcController/MyMvcMethod 。 MyMvcMethod使用MVC控制器中的[Authorized]属性进行修饰。
在Visual Studio 2010和2012中,使用Windows身份验证模式的开发服务器进行调试。 现在我正在尝试使用相同的解决方案的Visual Studio 2013,我得到401 - 未经授权的响应 。
我在全局applicationhost.config文件和项目属性中为我的MVC项目启用了Windows身份验证,我可以在浏览器中访问该方法,但控制台应用程序仍然获得401响应。 控制台应用程序也在我的Windows帐户下运行,因为我可以在任务管理器中验证它。
有谁知道怎么解决这个问题? 我只需要这个就可以在Visual Studio中调试IIS Express。
编辑:
我检查了IIS Express日志,子状态代码为2.因此根据MSDN,401.2引用“由于服务器配置登录失败”。
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".
最满意答案
我遇到过同样的问题。 简短的解决方法是允许IIS Express中的Windows身份验证:“\ Documents \ IISExpress \ config \ applicationhost.config”
更改
<windowsAuthentication enabled="false">至
<windowsAuthentication enabled="true">详细说明: 在VS2013中调试时的身份验证问题 - iis express
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);更多推荐
发布评论