我遇到了一个奇怪的问题,其中任何包含“PRN”的网址都会返回404。
如果我有两种方法:
public string Test(string x)
{
return "hello";
}
public string PRN(string x)
{
return "worked";
}
我可以通过导航到以下方式调用测试: 控制器/测试
它总会返回“你好”。但是,如果我试着打电话: 控制器/测试/ PRN,我得到404
如果我尝试调用Controller / PRN / Anything,我会得到404
在多个MVC3应用程序中,我发现任何包含“PRN”的URL都会返回404错误。有没有人有任何想法?
编辑: 这是我的路线配置:
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 }
);
}
感谢。
答案 0 :(得分:5)
答案 1 :(得分:-1)
如果您调用Controller/Test/PRN' It wont point to anything because you are calling the
Test` ActionMethod并传递PRN作为参数。
尝试添加...
routes.MapRoute(
"PRN", // Route name
"Controller/PRN/{x}", // URL with parameters
new { x = UrlParameter.Optional } // Parameter defaults
);
...在Global.asax.cs文件夹中的RegisterRoutes
方法的顶部。