2009-11-23 33 views
1

HttpForbiddenHandler類是密封的,但我想創建一個類,它的行爲。類似這樣的:模仿HttpForbiddenHandler類

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

    public bool IsReusable 
    { 
     get { return true; } 
    } 
} 

我將如何導致403重定向?

回答

3

如果你只是想發送403個狀態碼:

context.Response.Status = "403 Forbidden"; 

此外,您可能需要編寫一些信息給客戶端:

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

如果您希望將用戶重定向到在您的web.config或machine.config中配置的403自定義錯誤頁面,您應該可以這樣做:

throw new HttpException(403, "Forbidden");