【问题标题】:Route works locally, but fails on production路线在本地工作,但在生产中失败
【发布时间】:2013-09-18 18:24:32
【问题描述】:

我有一个静态路由,它基本上将 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.

如何诊断此问题?

【问题讨论】:

  • 您的生产服务器上没有任何重写规则设置?
  • 不,一个区别是有一个子域,即。 qa.example.com 在本地就像localhost:3424/getxml?...
  • 网址是如何创建/生成的?

标签: c# asp.net-mvc routes


【解决方案1】:

您的网址映射定义不正确。在当前状态下,您没有将 id 或大小映射到任何东西。您需要更新您的 URL 以实际映射到控制器的参数。将 URL 更新为类似

试试这样的:

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

【讨论】:

  • url模式不是controller/action/id/size,url是:www.example.com/getxml?userid=12&....
  • @user1361315 谢谢,请随时将路由图正确更新为您想要的模式。当我指出您的原始路由图实际上并未映射到任何东西时,无需对我的回答投反对票。
  • 它可以在本地工作吗?感谢您的回复,我不是投反对票的人!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-09-21
  • 2022-01-20
  • 2021-10-17
相关资源
最近更新 更多