【问题标题】:Redirect http Web Form Query String to https将 http Web 表单查询字符串重定向到 https
【发布时间】:2016-03-30 02:21:15
【问题描述】:

我已将旧的 Web 表单网站重新开发为 ASP MVC Web api。一些旧的 url 出现在搜索引擎和论坛上,带有旧的 Web 表单 URL 和查询字符串,我需要这些通过查询字符串 ID 查找并使用变量名重定向到新站点。我已将 ASP Web 表单页面添加到我的根 MVC 应用程序以执行重定向。问题是当我在我的本地主机上尝试代码时它可以工作,但是当我在实时网站上尝试它时它会重定向到主页。这可能是因为我有一个重写规则将所有 http: 重定向到 https。我不确定。

当前必应网址http://www.domain.com/View.aspx?ID=1

这适用于https://www.domain.com/View.aspx?ID=1(https 而不是 http)

重定向到http://www.domain.com/NewPath/SampleName

代码如下

try
{
  string url = "https://domain.com/NewPath/" + getNewName(Request.QueryString["id"]);
  Response.Redirect(url, false);
  HttpContext.Current.ApplicationInstance.CompleteRequest();
}
catch (Exception)
{
  Response.Redirect("https://domain.com");
}

Web 配置重写规则

<location path="app/views">
    <system.webServer>
      <staticContent>
        <clientCache cacheControlMode="DisableCache" />
      </staticContent>
    </system.webServer>
</location>

<rewrite>
      <rules>
        <rule name="SecureRedirect" stopProcessing="true">
          <match url="^(.*)$" />
          <conditions>
            <add input="{HTTPS}" pattern="off" />
            <add input="{HTTP_HOST}" pattern="^(www\.)?(.*)$" />
          </conditions>
          <action type="Redirect" url="https://{C:2}" redirectType="Permanent" />
        </rule>
      </rules>
</rewrite>

【问题讨论】:

    标签: c# asp.net-mvc redirect webforms


    【解决方案1】:

    IIS 重写规则

    <?xml version="1.0" encoding="UTF-8"?>
    <configuration>
        <system.webServer>
            <rewrite>
                <rules>
                    <rule name="Redirect to Https" stopProcessing="true">
                        <match url="(.*)" />
                        <conditions>
                            <add input="{HTTPS}" pattern="^OFF$" />
                        </conditions>
                        <action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="SeeOther" />
                    </rule>
                </rules>
            </rewrite>
        </system.webServer>
    </configuration>

    这个网址帮助了http://www.jppinto.com/2010/03/automatically-redirect-http-requests-to-https-on-iis7-using-url-rewrite-2-0/

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-04-17
      • 2016-12-14
      • 1970-01-01
      • 2013-09-22
      • 2014-12-03
      • 2013-04-15
      • 2017-06-02
      相关资源
      最近更新 更多