我已经为我的网站实现了一个自定义的HttpHandler,如果页面在列表中,它会将页面重定向到特定的页面。到目前为止,重定向工作正常,但问题是最终页面的内容变得空白。
来自我的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");
}
}
}
}与HttpHandler相关的Web.Config文件中的代码
<httpHandlers>
.
.
.
<add verb="*" path="*.aspx" type="CustomPageHandler, App_Code"/>
</httpHandlers>有人能帮我摆脱这种棘手的局面吗?先谢谢你...
发布于 2012-05-31 08:53:45
这是预期的行为。HttpHandler是实际处理请求的对象。如果请求不是对列表中某一页的请求,则代码不执行任何操作。这就是没有输出的原因。
如果您想修改页面的处理,而不是替换它,那么您需要一个HttpModule。
https://stackoverflow.com/questions/10825861
复制相似问题