从 MVC 3 应用程序中的 WCF Web API 返回 401 未经授权
我使用的是WCF Web API(最新版本,我认为是0.5,从VS2010 Ultimate集成包依赖GUI获得)。
我公开了一个简单的 API 类,并且在每个方法中我都进行了对用户执行授权的调用。当用户未经授权时,我会抛出 HttpResponseException 以及 401/未经授权的代码。
这有效,您可以看到在 Http Handler 链中的某个点,401 被捕获。问题在于 API 所在的站点包含 ASP.NET Forms 身份验证...因此,当它看到 401 时,它会尝试将我的客户端请求转发到登录页面。
如何针对我的网站中的特定子目录禁用此行为?我尝试设置“api”的位置始终允许用户...但我仍然抛出 401,这仍然导致 ASP.NET 尝试将我重定向到登录页面。
我确信我只是缺少一个简单的配置设置,该设置告诉 forms auth 忽略对 /api/* 目录的请求,但我找不到有关它的任何信息。
I'm using the WCF Web API (the latest version, which I think is 0.5, obtained from the VS2010 Ultimate integrated package dependency GUI).
I've got a simple API class exposed and in each method I'm making a call that performs authorization against the user. When the user is unauthorized, I throw an HttpResponseException with the 401/unauthorized code.
This works, and you can see that at some point in the Http Handler chain, the 401 was trapped. The problem is that the site in which the API resides contains ASP.NET Forms authentication... and so when it sees the 401, it tries to forward my client request to the logon page.
How do I disable this behavior for a particular sub-directory within my site? I've tried setting a location of "api" always allowing users... but I still throw a 401 which still causes ASP.NET to try and redirect me to the logon page.
I'm sure I'm just missing a simple configuration setting that tells forms auth to ignore requests for the /api/* directories, but I can't find any information on it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我已经在这里描述了问题及其解决方案(使用 Preview4): 使用 IIS 中托管的 WCF Web API 进行基本身份验证/获取 404 - 禁用表单身份验证重定向
I have described the problem and it's solution here (with Preview4): Basic Authentication with WCF Web API hosted in IIS / Getting a 404 - Disable Forms Authentication Redirection