【问题标题】:Url rewriting in asp.net?在asp.net中重写网址?
【发布时间】: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


【解决方案1】:

您在此处对所有可能的解决方案进行了出色的细分:http://weblogs.asp.net/scottgu/archive/2007/02/26/tip-trick-url-rewriting-with-asp-net.aspx

您使用的是哪个版本的 IIS?对于 IIS7 使用它自己的 URL 重写模块,对于 II6 使用 Intelligencia UrlRewriter.NET:http://urlrewriter.net/

【讨论】:

    猜你喜欢
    • 2016-11-03
    • 2011-01-23
    • 1970-01-01
    • 2010-10-08
    • 2018-07-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多