C# 模拟HttpForbiddenHandler类
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
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");