How to fix WebResource.axd JavaScript errors appearing when using asp.net routing

I had an issue with one of our asp.net 4.0 websites recently. The site was using web forms, routing and had .net validation controls in use. Everything worked great until I used the validation controls and discovered that I was getting 2 JavaScript errors on every page that used these controls.

I spent ages looking for a solution because I was looking for the wrong thing! I thought that the issue was to do with the .net runtime but it's actually to do with the routing side of things. What you need to do is tell .net to ignore the .axd files so that the JavaScript being referenced in the HTML will actually return a valid page.

Thankfully the fix couldn't be easier. In your global.asax file make sure you include an ignore rule for any axd files that your project might create. For example:

 

void Application_Start(object sender, EventArgs e) 
    {
        // Code that runs on application startup
        RegisterRoutes(RouteTable.Routes);
    }

    public static void RegisterRoutes(RouteCollection routes)
    {
        routes.Ignore("{resource}.axd/{*pathInfo}");
        // your page routes here
    }

blog comments powered by Disqus

Get In Touch

Follow me online at TwitterFacebook or Flickr.

Latest Tweets