In my application, Both mvc and web form is present.
But when I open any .aspx
page then in Application_Error
error is thrown.
The controller for path '/WebResource.axd' was not found or does not implement IController.
The controller for path '/ScriptResource.axd' was not found or does not implement IController.
I tried all these method, but none of them is working.
Added at top in RegisterRoutes method.
routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); routes.IgnoreRoute("{*allaspx}", new { allaspx = @".*\.aspx(/.*)?" });
Create a FileTypeConstraint class to check file ext.
.
public class FileTypeConstraint : IRouteConstraint
{
private readonly string[] MatchingFileTypes;
public FileTypeConstraint(string matchingFileType)
{
MatchingFileTypes = new[] { matchingFileType };
}
public FileTypeConstraint(string[] matchingFileTypes)
{
MatchingFileTypes = matchingFileTypes;
}
public bool Match(HttpContextBase httpContext, Route route, string parameterName, RouteValueDictionary values, RouteDirection routeDirection)
{
if (values["url"] != null)
{
string path = values["url"].ToString();
return MatchingFileTypes.Any(x => path.ToLower().EndsWith(x, StringComparison.CurrentCultureIgnoreCase));
}
else
{
return false;
}
}
And added this line at top and bottom both
routes.MapRoute(
"Defaultaxd",
"{*url}",
new { controller = "Home", action = "Index", id = UrlParameter.Optional },
new { myCustomConstraint = new FileTypeConstraint(new[] { "axd" }) }
);
Tried all these links.
Using URL Routing for Web Forms and StopRoutingHandler for Favicon