开发者

ASP.NET 4 migrate to routing / mapping

开发者 https://www.devze.com 2023-01-11 04:42 出处:网络
Previously I was using Rewriter.net to rewrite my urls. I used a format like: <rewrite url=\"~/(.*)_p(\\d+).aspx\\??(.*)\" to=\"~/product.aspx?pid=$2&amp;$3\"/>

Previously I was using Rewriter.net to rewrite my urls. I used a format like:

<rewrite url="~/(.*)_p(\d+).aspx\??(.*)" to="~/product.aspx?pid=$2&amp;$3"/>

So a page url would look like ~/productname_p21.aspx with an optional querystring.

I'm upgr开发者_StackOverflow社区ading the application to ASP.NET 4 and I would like to use the URL routing in System.Web.Routing, so I can get rid of the 3rd party library Rewriter.net.

I came up with this:

RouteTable.Routes.MapPageRoute("product", "product/{name}/{pid}", "~/product.aspx");

That's all fine, except for the fact that I want to put a 301 permanently moved status on the old-style URL's. How can I accomplish this with the .NET Routing library?

Thanks


A possible way of handling this situation:

Redirect Routes and other Fun With Routing And Lambdas

ASP.NET MVC tips: Routing Engine to aid SEO / 301 Redirect / Tracking

0

精彩评论

暂无评论...
验证码 换一张
取 消