Reputation: 443
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. So far the redirection is working fine but the issue is the content of the final page goes blank.
Code From My 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]
<httpHandlers>
.
.
.
<add verb="*" path="*.aspx" type="CustomPageHandler, App_Code"/>
</httpHandlers>
Anyone can help me to get out of this sticky situation? Thanks in advance...
Upvotes: 0
Views: 891
Reputation: 161831
This is the expected behavior. An HttpHandler is what actually processes the request. 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.
Upvotes: 3