【问题标题】:Redirect aspx page to another将aspx页面重定向到另一个
【发布时间】:2016-02-11 11:02:50
【问题描述】:

Windows Server 2008 R2。

我已经在我的服务器上安装了 URL Rewrite。我在将一个页面重定向到同一站点中的另一个页面时遇到困难,例如

我想重定向

www.mysite.com/content/old/content.aspx

到

www.mysite.com/content/new/content.aspx?id=1&sid=2

我已经尝试了几种方法来实现这一点,但事实证明比我想象的要困难。我怎么能只重定向一页?

我试过了

  <rewrite>
      <rewriteMaps configSource="Web.RewriteMaps.config"/>
      <rules>
          <rule name="Old Page Redirects" stopProcessing="true">
              <match url=".*"/>
              <conditions>
                  <add input="{OldPages:{REQUEST_URI}}" pattern="(.+)"/>
              </conditions>
              <action type="Redirect" url="{C:1}" appendQueryString="false" redirectType="Permanent"/>
          </rule>
      </rules>
  </rewrite>

在我的配置文件中

<rewriteMaps>
  <rewriteMap name="OldPages">
    <add key="/content/old/content.aspx" value="/content/new/content.aspx?id=1&sid=2" />
  </rewriteMap>
</rewriteMaps>

【问题讨论】:

  • 根据您的陈述“我尝试了几种方法”您尝试了什么应该添加问题。
  • 从您的回复来看,似乎有不止一种方法可以实现这一点?我尝试创建一个空白规则并选择我认为相关的选项,即请求的 URL = 匹配模式,使用完全匹配(但出现错误或我无法保存)。您能建议您认为哪种方式是正确的方式吗?

标签: asp.net redirect iis-7 windows-server-2008-r2


【解决方案1】:

另一种方法是将这样的内容添加到您的 asp.net 应用程序的 web.config 中(这将允许动态页面:

 <system.webServer>
 <httpRedirect enabled="true" destination="www.mysite.com/content/new/content.aspx?id=1&sid=2" />

对此我不确定。因为我从这个网站本身得到了这个。请也试试这个。

【讨论】:

  • 我认为重定向整个网站?我只需要一页
【解决方案2】:

你可以使用Response.Redirect("www.mysite.com/content/new/content.aspx?id=1&amp;sid=2");

将此代码写入您要使用的任何事件中。

例如:

protected void btnConfirm_Click(object sender, EventArgs e)
 {
   Response.Redirect("www.mysite.com/content/new/content.aspx?id=1&sid=2");
   }

我们也可以使用javascript进行导航。

window.location = "window.location = "SomePage.aspx";

【讨论】:

  • 我无法做到这一点,因为我无权访问文件背后的代码。希望在 IIS 中执行此操作
  • 我看到了那个链接,但它正在将一个目录重定向到一个页面,而不是一个页面到一个页面(除非我错过了什么?)
【解决方案3】:

终于找到了应该怎么做。

    <rewrite>
        <rules>
            <rule name="redirect single page" patternSyntax="ExactMatch" stopProcessing="true">
                <match url="old.aspx" />
                <action type="Redirect" url="URL/page.aspx" appendQueryString="false" />
            </rule>
        </rules>
    </rewrite>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-08-10
    • 2010-11-08
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多