Search code examples
asp.nethttp-redirecthttphandler

page not load when using httphandler


i use HttpHandler for redirect old php page to new aspx page. but when run project not load any page.

httpHandler:

public class Redirect:IHttpHandler
{
    public void ProcessRequest(HttpContext context)
    {
        string url = context.Request.Url.ToString().ToLower();
        if (url.Contains(".php"))
        {
            context.Response.AddHeader("Location", "../../fa/About.aspx");
            context.Response.StatusCode = 301;
            context.Response.End();
        }
    }

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

web.config

<system.webServer>
<handlers>
 <add name="Redirect" verb="*" path="*" type="ParsianTechnology.Utility.Redirect" />
</handlers>


Solution

  • You need do this change:

    <add name="Redirect" verb="*" path="*" type="ParsianTechnology.Utility.Redirect" />
    

    to

    <add name="Redirect" verb="*" path="*.php" type="ParsianTechnology.Utility.Redirect" />
    

    It should solve your problem.