如何在IIS 7.5中将https转换为http和反之? [英] How to convert https to http and viceversa in IIS 7.5?
问题描述
如何在IIS 7.5中将https转换为http并反之亦然?
我为某些用户提供内部网址,为其他用户提供外部网址。通过为其配置SSL证书来启用HTTPS。但是如果用户更改了
https://www.x.com必须自动重定向到http://www.x.com。同样在内部网址中,它必须更改https://192.168.4.1。到http://192.168.4.1以避免内部证书错误。
我看到这个
How to convert https to http and viceversa in IIS 7.5?
I have internal network url for a certain users and external url for few others. HTTPS was enabled by configuring SSL certificate for the same. But if the user changes
https://www.x.com must automatically redirect to to http://www.x.com. Similarly in internal url it must change https://192.168.4.1. to http://192.168.4.1 to avoid certificate error internally.
I saw this
<rule name="ForceHttpsBilling" stopProcessing="true">
<match url="(.*)billing/(.*)" ignoreCase="true" />
<conditions>
<add input="{HTTPS}" pattern="off" ignoreCase="false" />
</conditions>
<action type="Redirect" redirectType="Found" url="https://{HTTP_HOST}{REQUEST_URI}" />
</rule>
<!-- https:// to http:// rule -->
<rule name="ForceNonHttps" stopProcessing="true">
<match url="(.*)billing/(.*)" ignoreCase="true" negate="true" />
<conditions>
<add input="{SERVER_PORT}" pattern="^443$" />
</conditions>
<action type="Redirect" redirectType="Found" url="http://{HTTP_HOST}{REQUEST_URI}" />
</rule>
应该安装什么。还应该在HTTP_HOST和REQUEST_URL中设置什么。
What all should be installed. Also what should be set in HTTP_HOST and REQUEST_URL .
推荐答案
/ >
< / conditions >
< < span class =code-leadattribute> action type = 重定向 redirectType = 找到 url = http:// {HTTP_HOST} {REQUEST_URI } / >
< / rule >
" /> </conditions> <action type="Redirect" redirectType="Found" url="http://{HTTP_HOST}{REQUEST_URI}" /> </rule>
什么都应该安装。还应该在HTTP_HOST和REQUEST_URL中设置什么。
What all should be installed. Also what should be set in HTTP_HOST and REQUEST_URL .
我通常使用这样的东西,它一直对我有用。
你可以在global.asax中有这样的函数,可以在Application_BeginRequest中调用
private void RedirectToCorrectSSLScheme()
{
Uri pageRequest = Request.Url;
string requestPath = pageRequest.GetLeftPart(UriPartial.Path).ToLower();
requestPath = Server.UrlDecode(requestPath);
//如果给定页面应该是安全的,则PageIsSecure返回。我
//在XML配置中维护一个安全页面列表或
//安全目录。
bool securePage = GetSecurePages()。PageIsSecure(requestPath);
if(pageRequest.Scheme ==https&&!securePage && requestPath.Contains(。aspx ))
{
Response.Redirect(http://+ pageRequest.Host + pageRequest.PathAndQuery,true);
}
else if(pageRequest.Scheme ==http&& securePage && requestPath.Contains(。aspx))
{
回复.Redirect(https://+ pageRequest.Host + pageRequest.PathAndQuery,true);
}
}
I normally use something like this and it has always worked for me.
You can have a function like this in global.asax and can call in Application_BeginRequest
private void RedirectToCorrectSSLScheme()
{
Uri pageRequest = Request.Url;
string requestPath = pageRequest.GetLeftPart(UriPartial.Path).ToLower();
requestPath = Server.UrlDecode(requestPath);
// PageIsSecure returns if the given page should be secure or not. I
//maintain a list of secure pages or
//secure directory in an XML config.
bool securePage = GetSecurePages().PageIsSecure(requestPath);
if (pageRequest.Scheme == "https" && !securePage && requestPath.Contains(".aspx"))
{
Response.Redirect("http://" + pageRequest.Host + pageRequest.PathAndQuery, true);
}
else if (pageRequest.Scheme == "http" && securePage && requestPath.Contains(".aspx"))
{
Response.Redirect("https://" + pageRequest.Host + pageRequest.PathAndQuery, true);
}
}
这篇关于如何在IIS 7.5中将https转换为http和反之?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!