配置 asp.net mvc hocalhost/Products.aspx 到 hocalhost/Products
如何配置 asp.net mvc 路由以将 301
hocalhost/Products.aspx 和 hocalhost/Search.aspx
永久重定向到
hocalhost/Products 和 hocalhost/Search
,即从路径中删除 .aspx 扩展名?
How to configure asp.net mvc routing to redirect permanently 301
hocalhost/Products.aspx and hocalhost/Search.aspx
to
hocalhost/Products and hocalhost/Search
i.e. to remove .aspx extension from the path?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
按照这些思路做一些事情应该可以解决问题。映射以下路由:
并在控制器中定义一个
Redirect
操作:您可以将两个
aspx
页面重定向到同一重定向路由,并通过解析 < code>HttpContext.Request.RawUrl (不过对于最后一点可能有更好的方法)。更新
确实有一种更简单的方法,正如@alex自己发现的那样。为了获取原始请求中的文件,只需执行以下操作:
Something along these lines should do the trick. Map the following route:
And define a
Redirect
action in your controller:You could redirect both
aspx
pages to the same redirect route and detect which file has actually been invoked by parsingHttpContext.Request.RawUrl
(there might be a better way for this last point though).UPDATE
There is indeed a simpler way, as found out by @alex himself. In order to get the file in the original request, just do: