【发布时间】:2014-06-17 16:10:15
【问题描述】:
假设我有两台服务器。一个使用 https 证书运行,而另一个则没有。 访问我的网站之一的用户键入 http。如果该站点指向具有 https 证书的服务器,那么我想重定向用户/重写 url。
只剩下一件事了。如何检查我的网站是否获得了证书?或者如果绑定是https?
void Application_BeginRequest(object sender, EventArgs e)
{
var path = HttpContext.Current.Request.Url.AbsolutePath;
var variableToSeeIfIISSiteRunningOnCertificate = true;
if (variableToSeeIfIISSiteRunningOnCertificate && !HttpContext.Current.Request.IsSecureConnection && !string.IsNullOrEmpty(path) && path.ToLower().Contains("loginpage.aspx"))
{
HttpContext.Current.Response.Redirect(HttpContext.Current.Request.Url.AbsoluteUri.Replace("http://", "https://"));
}
}
【问题讨论】: