我的 ASP.NET MVC 路线有什么问题吗?
我的 ASP.NET MVC 应用程序中有一些路由可以处理旧 URL 的重定向。我重定向的 URL 是:
contentSpanishContentList.aspx
这是路线:
routes.MapRoute("RedirectLegacyContent1",
"content{contentUri}.aspx",
new { controller = "Redirect", action = "Content", contentUri = string.Empty, contentId = 0 });
问题是它显示为未找到。我发现问题是(粗体)contentSpanish*Content*List.aspx。我应该怎么做才能使这条路线适用于这种情况?
I have some routes in my ASP.NET MVC application that handle redirecting of old urls. The URL I'm redirecting is:
contentSpanishContentList.aspx
Here's the route:
routes.MapRoute("RedirectLegacyContent1",
"content{contentUri}.aspx",
new { controller = "Redirect", action = "Content", contentUri = string.Empty, contentId = 0 });
The problem is it comes up as not found. I figured out that the problem is (in bold) contentSpanish*Content*List.aspx. What should I do to make this route work with this case?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
两种解决方案
content
)。GetRouteData
方法。如果您计划仅将此路由用于传入请求(不在视图中生成任何 URL 来指向任何这些页面,即使用Url.Action
或Html.ActionLink< /code>) 那么最简单的方法是生成类似
RegExRoute
的东西,它很容易编写,也很容易解决此类请求。第一个是简单的,第二个是通用的。
Two solutions
content
).GetRouteData
method. And if you're planning to only use this route for incoming requests (not generating any URLs in your views to point to any of these pages ie. usingUrl.Action
orHtml.ActionLink
) then the easiest way would be to generate something like aRegExRoute
which would be easy to write and also easy to resolve these kind of requests.The fist one is simple, the second is universal.
使用 Fiddler 查看发生了什么。 404 是在第一次请求时发生的吗?或者是在重定向之后发生的?
安装RouteDebugger 包,看看它告诉你什么。
Use Fiddler to look at what's happening. Is the 404 happening on the first request? Or is it happening after the redirect?
Install the RouteDebugger package and see what it tells you.