I've been trawling through 1000s of questions and blogs and still don't fully understand dam routing!
Along the lines of Scott Hanselman's blog I am trying to route a certain call to a .GIF to a custom HttpHandler while the rest of the MVC4 site behaves normally. I'm 90% of the way there.
So in the my RouteConfig I have
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.Add("AnalyticsRoute", new Route("analytics/a.gif", new AnalyticsRouteHandler()));
routes.MapRoute("Default", "{controller}/{action}/{id}", new { controller = "Home", action = "Index", id = UrlParameter.Optional });
routes.RouteExistingFiles = true;
}
and in my web.config I have
<handlers>
...
<add name="analytics" verb="*" path="analytics/a.gif" type="Lms.Analytics.AnalyticsHandler, Lms.Analytics" preCondition="managedHandler" />
</handlers>
Now this way, http://mysite.com/analytics/a.gif routes correctly and all is happy, however all my ActionLinks are resolving as http://mysite.com/analytics/a.gif?action=Index&controller=Category
If I reverse the order in the RouteConfig i.e.
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute("Default", "{controller}/{action}/{id}", new { controller = "Home", action = "Index", id = UrlParameter.Optional });
routes.Add("AnalyticsRoute", new Route("analytics/a.gif", new AnalyticsRouteHandler()));
routes.RouteExistingFiles = true;
}
All the links resolve just fine, but a call to http://mysite.com/analytics/a.gif results in a 404 error?
I must be doing something stupid and just can't see it?!
Thanks in advance