开发者

Mimic the HttpForbiddenHandler Class

开发者 https://www.devze.com 2022-12-12 02:15 出处:网络
The HttpForbiddenHandler Class is sealed however I\'d like to create a class that behaves like it. Something like this:

The HttpForbiddenHandler Class is sealed however I'd like to create a class that behaves like it. Something like this:

public class ForbiddenHandler : IHttpHandler
{
    public void ProcessRequest(HttpContext context)
    {
        // do the 403 here somehow
    }

    public bool IsReu开发者_如何转开发sable
    {
        get { return true; }
    }
}

How would I cause that 403 redirect?


If you simply want to send the 403 status code:

context.Response.Status = "403 Forbidden";

Also, you might want to write some message to the client:

context.Response.Write("This is very much forbidden!");

If you wish to redirect the user to the 403 custom error page, configured in your web.config or machine.config, you should be able to do it like this:

throw new HttpException(403, "Forbidden");
0

精彩评论

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