【发布时间】:2012-06-08 18:49:24
【问题描述】:
我正在开发 asp.net 网络应用程序。
请指导我在 asp.net 中重写 url:
我需要更改以下链接
http://www.faredepot.com/ViewArticle.aspx?aid=1
到
http://www.faredepot.com/Cheap_Flights_to_Atlanta.html
我怎样才能做到这一点,我尝试如下
void Application_BeginRequest(object sender, EventArgs e) {
string fullOrigionalpath = Request.Url.ToString();
if (fullOrigionalpath.Contains("http://www.faredepot.com/Cheap_Flights_to_Atlanta.html")) {
Context.RewritePath("http://www.faredepot.com/ViewArticle.aspx?aid=1");
}
}
或者尝试在 web.config 中这样做
<rewriter>
<rewrite url="http://www.faredepot.com/ViewArticle.aspx?aid=1" to="http://www.faredepot.com/Cheap_Flights_to_Atlanta.htm" />
</rewriter>
【问题讨论】:
-
你在使用 VS 2010 吗?如果你是,ASP.NET Routing 是最好的选择,msdn.microsoft.com/en-us/library/dd329551.aspx
-
很好,使用 ASP.NET 路由。此外,我还编写了一个可以提供帮助的 Navigation 项目 navigation.codeplex.com 。如果您有兴趣并需要任何帮助,请告诉我
-
@grahammendick 非常感谢 :)
-
如果对您有帮助,请不要忘记接受答案...
标签: asp.net url-rewriting url-routing