"Sys is undefined" error because WebResource.axd is returning the wrong content
I'm getting the dreaded "Microsoft JScript runtime error: 'Sys' is undefined" error while trying to develo开发者_开发问答p a site in ASP.NET on .NET framework 4.0. This was working fine until I tried programmatically adding items to a menu, and this started happening. While debugging, I pointed Fiddler at my app and found that the request for the WebResource.axd is returning successfully (code == 200), but the response text is the whole html page and NOT the javascript that it is supposed to be returning, and this is why Sys is undefined.
What's going on here? Any help much appreciated. Thanks.
Solved, thanks to this. I'm using ASP.NET Routing, and I was routing root level requests like http://www.mysite.com/{PageId}
, and this matching pattern is so general that it was also matching the request for /WebResource.axd
, and that's why the page request for the axd file was being routed to an aspx page instead of the usual handler. Not what I would have expected, but I can see the logic.
The fix is to tell the routing system to ignore this particular kind of request:
RouteTable.Routes.Ignore("{resource}.axd/{*pathInfo}")
精彩评论