开发者

MVC3 404 for any URL containing "PRN"

开发者 https://www.devze.com 2023-03-18 15:39 出处:网络
I have run into a strange issue where any URL containing \"PRN\" will retur开发者_运维百科n a 404.

I have run into a strange issue where any URL containing "PRN" will retur开发者_运维百科n a 404.

If I have 2 methods:

    public string Test(string x)
    {
        return "hello";
    }

    public string PRN(string x)
    {
        return "worked";
    }

I can call test by navigating to: Controller/Test

It will always return "hello." However, if I try to call: Controller/Test/PRN, I get a 404

If I attempt to call Controller/PRN/Anything, I get a 404

In multiple MVC3 applications, I have found that any URL containing "PRN" will return a 404 error. Does anyone have any ideas?

EDIT: This is my route configuration:

    public static void RegisterRoutes(RouteCollection routes)
    {
        routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

        routes.MapRoute(
            "Default", // Route name
            "{controller}/{action}/{id}", // URL with parameters
            new { controller = "Home", action = "Index", id = UrlParameter.Optional } 
        );

    }

Thanks.


You should have a read a this : http://bitquabit.com/post/zombie-operating-systems-and-aspnet-mvc/

Which points to : ASP.NET MVC Routing vs. Reserved Filenames in Windows


If you call Controller/Test/PRN' It wont point to anything because you are calling theTest` ActionMethod and passing PRN as the parameter.

Try adding ...

routes.MapRoute(
            "PRN", // Route name
            "Controller/PRN/{x}", // URL with parameters
            new { x = UrlParameter.Optional } // Parameter defaults
        );

... to the top of your RegisterRoutes method in Global.asax.cs folder.

0

精彩评论

暂无评论...
验证码 换一张
取 消