【发布时间】: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