【问题标题】:URL Re-Write using C# [closed]使用 C# 重写 URL [关闭]
【发布时间】:2012-07-17 21:31:07
【问题描述】:

我正在开发 ASP.NET 网站(VS 2010,Framework 4.0)。

如何使用 C# 重写页面的 URL?有没有可用的第三方工具?谁能帮我解决这个问题?

【问题讨论】:

标签: c# asp.net url-rewriting


【解决方案1】:
void Application_BeginRequest(object sender, EventArgs e)
{
    // Get the current path
    string CurrentURL = Request.Url.ToString();
     // Condition
    if (CurrentURL.Contains("HtmlResponce.aspx"))
    {
        HttpContext MyContext = HttpContext.Current;

        // Re write here
        MyContext.RewritePath("testPage.aspx");
    }
}

我在 Global.asax 中尝试了这段代码。它对我有用!

【讨论】:

    【解决方案2】:

    如果您使用的是 IIS 7.x,最好使用 URL-Rewriting Module 2.0,从这里:http://learn.iis.net/page.aspx/664/using-url-rewrite-module-20/

    上面发布的链接指向在 IIS6 时代使用的“旧”技术。

    IIS 7.x 的新选项更加简单方便。

    【讨论】:

      猜你喜欢
      • 2012-01-12
      • 2015-03-08
      • 2021-02-25
      • 2013-12-01
      • 1970-01-01
      • 2021-03-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多