开发者

ASP.Net converts 401 to 302 error codes

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

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

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?


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_codes


Sounds like you have authentication turned on for the page. If this is the case, then your app is calling Authentication before the hand off to your custom handler. That's why you see the login page.

The isAuthorized in your handler is populated before your handler receives the call. You'll want to use a module and hook into the Authentication Life Cycle Event. See the Asp.Net Life Cycle

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜