ASP.NET MVC 中的 MapRoute 问题(针对 IIS6)
我在服务器(IIS6)上的路由有问题。它在开发环境上工作正常:
routes.MapRoute(
"FindCities",
"FindCities/{state_id}",
new { controller = "Regions", action = "FindCitiesByStateID", state_id = "" });
这里我称之为此操作:
$.ajax({
type: "GET",
contentType: "application/json; charset=utf-8",
url: "FindCities/" + state_id,
data: "{}",
dataType: "json"
...
我拥有的所有路线:
routes.MapRoute(
"Default",
"{controller}.aspx/{action}/{id}",
new { action = "Index", id = "" }
);
routes.MapRoute(
"Root",
"",
new { controller = "Home", action = "Index", id = "" }
);
我尝试过 url: "FindCities.aspx/" + state_id 和 "FindCities.aspx/{state_id}" 和其他变体,但它没有找不到正确的方法。 为 IIS6 编写路由的正确方法是什么? TIA
I have a problem in routing on the server (IIS6). It works OK on the development environment:
routes.MapRoute(
"FindCities",
"FindCities/{state_id}",
new { controller = "Regions", action = "FindCitiesByStateID", state_id = "" });
Here I call this action:
$.ajax({
type: "GET",
contentType: "application/json; charset=utf-8",
url: "FindCities/" + state_id,
data: "{}",
dataType: "json"
...
All routes i have:
routes.MapRoute(
"Default",
"{controller}.aspx/{action}/{id}",
new { action = "Index", id = "" }
);
routes.MapRoute(
"Root",
"",
new { controller = "Home", action = "Index", id = "" }
);
I've tried url: "FindCities.aspx/" + state_id and "FindCities.aspx/{state_id}" and other variants, but it doesn't find the right way.
What is the right way to write routes for IIS6?
TIA
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我已经写了一个直接的url,如果你知道如何为IIS6编写路由请回答
I've written a direct url, if you know how to write Routes for IIS6 please answer
@1gn1ter你有没有考虑过在jquery.ajax url上使用@Url.Action("")方法?通过使用@Url.Action(""),你可以让它在运行时解析你的整个url。因此它将在开发和生产环境上都匹配。
如果您需要使用该特定路由,您还可以使用 @Url.RouteUrl() 将您的路由名称作为参数传递。
示例
@1gn1ter have you considered using on you jquery.ajax url the @Url.Action("") method? By using @Url.Action("") you let it resolve your entire url on runtime. Thus it will match both on development and production environment.
If you need to use that specific route, you can also use @Url.RouteUrl() passing your route name as a parameter.
EXAMPLE