You don't have to remap URLs in IIS, you can remap them in web.config. For example, you can create an HTTP Handler (.ashx extension) with this code:
Code:
public class MyHandler : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/plain";
context.Response.Write("Hello World");
}
public bool IsReusable
{
get
{
return false;
}
}
}
You can then remap existing URLs to this new handler in web.config:
Code:
<urlMappings enabled="true">
<add url="~/SomeUrl.aspx" mappedUrl="~/MyHandler.ashx"/>
</urlMappings>
So, I would only remap the exceptions to your own HttpHandler and not all extensions which then requires you to try and find out what your code can handle and then give the rest back to the framework.
Alternatively, if you still want to do it from your own handler (not recommended), you can do something like this in ProcessRequest of the IHttpHandler:
Code:
if (someCondition)
{
string virtualPath = "~/Default.aspx";
string physicalPath = context.Server.MapPath(virtualPath);
IHttpHandler handler = PageParser.GetCompiledPageInstance(virtualPath, physicalPath, context);
handler.ProcessRequest(context);
context.ApplicationInstance.CompleteRequest();
}
Be aware of a few issues though: first: this new ProcessRequest will probably trigger your handler again which will call ProcessRequest which will trigger your handler which will call , well, I think you get the idea. You need to code some stuff to avoid that.
Also, not 100%, but there might be some issues with regard to caching when you execute pages like this. You may want to read up on IHttpHandler and IHttpHandlerFactory if you continue down this path.
Cheers,
Imar