简体   繁体   English

HttpHandler实现

[英]HttpHandler implementation

I have implemented a custom HttpHandler for my website which will redirect the page to a specific page if the page is in a list. 我为我的网站实现了一个自定义HttpHandler,如果页面在列表中,该页面会将页面重定向到特定页面。 So far the redirection is working fine but the issue is the content of the final page goes blank. 到目前为止,重定向工作正常,但问题是最后一页的内容空白。

Code From My PageHandler: 来自我的PageHandler的代码:

public class CustomPageHandler : IHttpHandler
{
    public bool IsReusable
    {
        get { return false; }
    }

    public void ProcessRequest(HttpContext context)
    {
        List<string> fileList = new List<string>();
        fileList.Add("Page1.aspx");
        fileList.Add("Page2.aspx");

        foreach (string fileName in fileList)
        {
            if (context.Request.RawUrl.ToLower().Contains(fileName.ToLower()))
            {
                context.Response.Redirect("BlockedPage.aspx");
            }
        }
    }
}

Code from my Web.Config file [Related to HttpHandler] 我的Web.Config文件中的代码[与HttpHandler相关]

<httpHandlers>
   .
   .
   .
   <add verb="*" path="*.aspx" type="CustomPageHandler, App_Code"/>
</httpHandlers>

Anyone can help me to get out of this sticky situation? 有人可以帮助我摆脱这种棘手的情况吗? Thanks in advance... 提前致谢...

This is the expected behavior. 这是预期的行为。 An HttpHandler is what actually processes the request. HttpHandler是实际处理请求的内容。 Your code does nothing if the request is not a request to one of the pages in the list. 如果该请求不是对列表中页面之一的请求,则您的代码不执行任何操作。 That's why there is no output. 这就是为什么没有输出的原因。

If you want to modify the processing of pages instead of replacing it, then you need an HttpModule. 如果要修改页面处理而不是替换页面处理,则需要HttpModule。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM