【发布时间】:2017-03-14 22:39:21
【问题描述】:
我有一个网站最近从 http:// 移动到 https://
该站点是使用托管在 IIS7 上的 MVC 构建的,我知道我应该为此设置 4 个绑定。
主要的:
https://www.example.com(端口:443 - ip地址:*)
和其他 3 个人都到 301 重定向到上述内容。
http://www.example.com - (port:80 - ip address: * -re-direct works)
http://example.com - (port:80 - ip address: * -re-direct works)
https://example.com - (port:443 - ip address: * -re-direct does not work)
试图解决为什么底部的失败,无法访问站点。找不到服务器 DNS 地址。
下面是我用来将 http 重定向到 https 的代码
// The base only redirects GET, but we added HEAD as well. This avoids exceptions for bots crawling using HEAD.
// The other requests will throw an exception to ensure the correct verbs are used.
// We fall back to the base method as the mvc exceptions are marked as internal.
if (!String.Equals(filterContext.HttpContext.Request.HttpMethod, "GET", StringComparison.OrdinalIgnoreCase)
&& !String.Equals(filterContext.HttpContext.Request.HttpMethod, "HEAD", StringComparison.OrdinalIgnoreCase))
{
base.HandleNonHttpsRequest(filterContext);
}
// Redirect to HTTPS version of page
// We updated this to redirect using 301 (permanent) instead of 302 (temporary).
string url = "https://" + filterContext.HttpContext.Request.Url.Host + filterContext.HttpContext.Request.RawUrl;
filterContext.Result = new RedirectResult(url, true);
您知道底部装订出了什么问题吗?试图在 Google Webmaster Search Console 上设置第 4 个属性,显然由于 DNS 失败而无法设置。
非常感谢任何帮助。干杯
【问题讨论】: