ASP.Net转换401到302错误codeS [英] ASP.Net converts 401 to 302 error codes

查看:180
本文介绍了ASP.Net转换401到302错误codeS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个定制的处理程序,并在某些情况下,我要指示给用户代理,他们没有被授权(HTTP错误code 401)

I have a custom handler and in some cases, I want to indicate to the user agent that they are not authorized (Http Error Code 401)

        if (!IsAuthorized(context))
        {
            context.Response.StatusCode = 401;
            context.Response.End();
            return;
        }

当我进入我的处理程序,实际上我得到一个302重定向到表单认证页面。有没有办法来阻止这种情况发生?

When I access my handler, I am actually getting a 302 and a redirect to the forms authentication page. Is there a way to stop this from happening?

推荐答案

您的场景听起来像一个拒绝访问,而不是山寨版。你可以使用403是HTTP状态code为拒绝访问?

Your scenario sounds like an "Access denied" instead of "unauthorized". Could you use 403 which is the HTTP status code for "Access denied"?

http://en.wikipedia.org/wiki/List_of_HTTP_status_$c$cs

这篇关于ASP.Net转换401到302错误codeS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆