我们有一个自托管的 DNN 6.01.03 站点,在 Windows 2003x64 中,std。
我们已启用它以使用 SSL,但我们希望对其进行设置,以便通过 HTTP 的用户被重定向到 HTTPs。
有没有办法做到这一点?似乎在 IIS7 中我们可以使用 IIS Rewrite URL 模块,但这是 IIS6。
请指教。谢谢。
我们有一个自托管的 DNN 6.01.03 站点,在 Windows 2003x64 中,std。
我们已启用它以使用 SSL,但我们希望对其进行设置,以便通过 HTTP 的用户被重定向到 HTTPs。
有没有办法做到这一点?似乎在 IIS7 中我们可以使用 IIS Rewrite URL 模块,但这是 IIS6。
请指教。谢谢。
最快的方法是在 DNN 中将站点设置为“强制 SSL”。
我注意到当使用来自 IFinity.com.au 的 UrlMaster 之类的工具时,这种行为会更好。
设置一个重定向页面并在那里指出 403.4 错误。重定向页面将是唯一不强制 SSL 的 url。
您可以在这里使用几乎所有可用的网络技术。
例子:
在 ASP.NET 中,redirect.aspx 的编写方式与经典 ASP 中的编写方式类似:
<%@ Page Language="C#" %>
<!DOCTYPE html>
<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
if (!Request.IsSecureConnection)
{
string query = Request.ServerVariables["QUERY_STRING"];
query = query.Replace("http:", "https:");
query = query.Replace("403;", "");
query = query.Replace(":80", "");
Response.Redirect(query);
}
}
</script>
<html>
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
Redirecting...
</div>
</form>
</body>
</html>
您可以设置重定向Global.asax
以强制重定向托管域上的所有页面请求。这将比任何 DNN 设置具有更高的优先级。
<script RunAt="server">
protected void Application_BeginRequest(object sender, EventArgs e)
{
// ENABLE SSL REDIRECTS
if (!HttpContext.Current.Request.IsSecureConnection)
{
Response.Redirect("https://" + Request.ServerVariables["HTTP_HOST"] + HttpContext.Current.Request.RawUrl);
}
}
</script>
或者,如果您使用自定义标头或负载均衡器
<script RunAt="server">
protected void Application_BeginRequest(object sender, EventArgs e)
{
// ENABLE SSL REDIRECTS
if (!string.Equals(Request.Headers["X-Forwarded-Proto"], "https", StringComparison.InvariantCultureIgnoreCase))
{
Response.Redirect("https://" + Request.ServerVariables["HTTP_HOST"] + HttpContext.Current.Request.RawUrl);
}
}
</script>