Route在本地工作,但在生产时失败

时间:2013-09-18 18:24:32

标签: c# asp.net-mvc routes

我有一条静态路由,它基本上将url模式映射到特定的控制器动作。

routes.MapRoute(
name: "StaticRoute1", url: "getxml", defaults: new { Controller = "XmlData", Action = GetXml" });

所以网址如下:

www.example.com/getxml?id=1&size=100

应调用XmlDataController GetXml方法。

它在当地运作良好,但在生产中我得到:

路由表中没有路由与提供的值匹配。

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.InvalidOperationException: No route in the route table matches the supplied values.

如何诊断此问题?

1 个答案:

答案 0 :(得分:-2)

您错误地定义了您的网址映射。在它的当前状态中,你没有将id或大小映射到任何东西。您需要更新URL以实际映射到控制器的参数。将URL更新为

尝试这样的事情:

routes.MapRoute(
   name: "StaticRoute1",
   url: "{controller}/{action}/{id}/{size}",
   defaults: new { controller = "myController", action = "getxml", id = 1, size = 200 }
);