使用IIS Express 8.0在Visual Studio 2013中进行调试时,无法使用Windows身份验证访问[授权] MVC方法(Can't access [Authorized

编程入门 行业动态 更新时间:2024-10-22 14:02:39
使用IIS Express 8.0在Visual Studio 2013中进行调试时,无法使用Windows身份验证访问[授权] MVC方法(Can't access [Authorized] MVC method using Windows Authentication when debugging in Visual Studio 2013 using IIS Express 8.0)

我在解决方案中有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);

更多推荐

本文发布于:2023-08-07 09:43:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1463782.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:身份验证   方法   Studio   Visual   IIS

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!