开发者

Mimic the HttpForbiddenHandler Class

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜