Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/35.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 模拟HttpForbiddenHandler类_C#_Asp.net_Security - Fatal编程技术网

C# 模拟HttpForbiddenHandler类

C# 模拟HttpForbiddenHandler类,c#,asp.net,security,C#,Asp.net,Security,HttpForbiddenHandler类是密封的,但是我想创建一个行为与之类似的类。大概是这样的: public class ForbiddenHandler : IHttpHandler { public void ProcessRequest(HttpContext context) { // do the 403 here somehow } public bool IsReusable { get { retur

HttpForbiddenHandler类是密封的,但是我想创建一个行为与之类似的类。大概是这样的:

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

    public bool IsReusable
    {
        get { return true; }
    }
}
throw new HttpException(403, "Forbidden");

我将如何导致403重定向?

如果您只想发送403状态代码:

context.Response.Status = "403 Forbidden";
此外,您可能希望向客户端写入一些消息:

context.Response.Write("This is very much forbidden!");
如果您希望将用户重定向到在web.config或machine.config中配置的403自定义错误页面,您应该可以这样做:

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

    public bool IsReusable
    {
        get { return true; }
    }
}
throw new HttpException(403, "Forbidden");