401响应code与ASP.NET MVC JSON请求 [英] 401 response code for json requests with ASP.NET MVC
问题描述
如何禁用401响应code标准ASP.NET处理(重定向到登录页面)对AJAX / JSON请求?
How to disable standard ASP.NET handling of 401 response code (redirecting to login page) for AJAX/JSON requests?
有关网页的网页也没关系,但AJAX我需要得到正确的401错误code,而不是漂亮的二百分之三百○二登录页面。
For web-pages it's okay, but for AJAX I need to get right 401 error code instead of good looking 302/200 for login page.
更新:
有来自菲尔哈克,ASP.NET MVC的PM几种解决方案 - <一个href=\"http://haacked.com/archive/2011/10/04/$p$pvent-forms-authentication-login-page-redirect-when-you-donrsquot-want.aspx\">http://haacked.com/archive/2011/10/04/$p$pvent-forms-authentication-login-page-redirect-when-you-donrsquot-want.aspx
推荐答案
在ASP.NET运行时开发,使其始终将用户重定向如果的Htt presponse.Status $ C $ ç
设置为401,但只有当&LT;认证/方式&gt;
的Web.config的部分找到
The ASP.NET runtime is developed so that it always will redirect the user if the HttpResponse.StatusCode
is set to 401, but only if the <authentication />
section of the Web.config is found.
删除验证部分将要求您实现重定向到您的属性登录页面,但是这不应该是一个大问题。
Removing the authentication section will require you to implement the redirection to the login page in your attribute, but this shouldn't be a big deal.
这篇关于401响应code与ASP.NET MVC JSON请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!