I’m using the following route handler to route urls in a .net 4.0 solution. The route handler, by default, ignores files that exists, and it’s exactly what I need because I don’t want to map css files, js files, images files, etc.
A change in the webconfig (adding the customerros section) forced me to notice a bug. If there’s a link for a image, and the image doesn’t exists, the url is mapped, causing a lot of trouble (errors).
Now what I need is to completely ignore a file extension (js, css, jpg, gif, etc) or, preferable, only map .aspx files. But I’m not sure how to do that.
ps: the website is based on user uploads, a percentual of broken links will always exists.
public class RouteHandler : IRouteHandler
{
private readonly string _path;
public RouteHandler(string path)
{
_path = path;
}
public IHttpHandler GetHttpHandler(RequestContext requestContext)
{
Page page = BuildManager.CreateInstanceFromVirtualPath(_path, typeof(Page)) as Page;
foreach (KeyValuePair<string, object> i in requestContext.RouteData.Values)
{
HttpContext.Current.Items[i.Key.Replace("*", "")] = i.Value;
}
return page;
}
}
routes.Add("somename", new Route("folder/insidefolder", null, null, new RouteHandler("~/folder-insidefolder.aspx")));
I think the following line solves the image problem (need more tests):