Difficulty Ignoring Route In Asp.Net Mvc

筅森魡賤 提交于 2019-12-08 04:37:44

问题


The following exception is being thrown after an IgnoreRoute method call:

The controller for path '/anything.php' was not found or does not implement IController.

However, I have the following method in my MvcApplication class:

public static void RegisterRoutes(RouteCollection routes)
{
    routes.RouteExistingFiles = false;

    routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

    routes.IgnoreRoute("{*php}", new { php = @"(/?.*/)*\.php$" });

    // Some calls to routes.MapRoute occur here.
}

I'm not really sure why the exception is being thrown if the Mvc website is set up to ignore such routes. Also, I'm testing the site by hitting F5 in Visual Studio and then replacing http://localhost:12345/ by http://localhost:12345/anything.php. Any help is much appreciated!

Thanks,

Andrew


回答1:


Have you checked your regular expression to make sure it's .NET compatible?

Try replacing your regex with this regex:

routes.IgnoreRoute("{*allphp}", new {allphp=@".*\.php(/.*)?"})


来源:https://stackoverflow.com/questions/6351727/difficulty-ignoring-route-in-asp-net-mvc

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!