一百分,如何使在浏览器输入http://xxx会自动跳到https://
我在做一个网站,要使用SSL,我发现像PaiPai.com等网站,任意页面,如果使用http访问,都会自动跳到https,这是怎么实现的?
用客户端JS或者服务器Response.Redirect肯定不行。因为我所有页面都要求使用SSL访问。用Http是访问不了的。
我觉得应该是要接管Http Module来实现,但具体怎么做就不清楚了,麻烦哪位大侠说说。
------解决方案--------------------不懂。帮顶
------解决方案--------------------Response.Redirect( string.Format( "https://{0}/{1}/{2} ", Request.Url.Host, Request.ApplicationPath,Request.RawUrl));
这样吧
------解决方案-------------------- <P> First, we define a custom configuration class so we can place our URL base
strings into web.config: </P>
<DIV class=precollapse id=premain0 style= "WIDTH: 100% "> <IMG id=preimg0
style= "CURSOR: hand " height=9 src= "http://www.codeproject.com/images/minus.gif "
width=9 preid= "0 "> Collapse </DIV> <PRE lang=cs id=pre0 style= "MARGIN-TOP: 0px "> using System;
using System.Configuration;
namespace AA.switchprotocol
{
public class SwitchProtocolSection : ConfigurationSection
{
[ConfigurationProperty( "urls ", IsRequired = true)]
public UrlsFormElement Urls
{
get { return (UrlsFormElement)base[ "urls "]; }
}
}
public class UrlsFormElement : ConfigurationElement
{
[ConfigurationProperty( "baseUrl ", IsRequired = true)]
public string BaseUrl
{
get { return (string)base[ "baseUrl "]; }
}
[ConfigurationProperty( "baseSecureUrl ", IsRequired = true)]
public string BaseSecureUrl
{
get { return (string)base[ "baseSecureUrl "]; }
}
}
} </PRE>
------解决方案--------------------Now we can define our base URL strings in web.config:
<?xml version= "1.0 "?>
<configuration>
<configSections>
<section
name= "SwitchProtocol "
type= "AA.switchprotocol.SwitchProtocolSection, __code "/>
</configSections>
<SwitchProtocol>
<urls baseUrl= "http://localhost "
baseSecureUrl= "https://localhost " />
</SwitchProtocol>
<system.web>
<compilation debug= "false "/>
</system.web>
------解决方案-------------------- <P> Next, define a simple accessor to the confiuration settings: </P> <PRE lang=cs> using System;
using System.Web.Configuration;
namespace AA.switchprotocol
{
public static class Globals
{
public readonly static SwitchProtocolSection Settings =
(SwitchProtocolSection)WebConfigurationManager.
GetSection( "SwitchProtocol ");
}
} </PRE>
<P> Implement a base page class with custom redirect logic: </P>
<DIV class=precollapse id=premain3 style= "WIDTH: 100% "> <IMG id=preimg3
style= "CURSOR: hand " height=9 src= "http://www.codeproject.com/images/minus.gif "
width=9 preid= "3 "> Collapse </DIV> <PRE lang=cs id=pre3 style= "MARGIN-TOP: 0px "> using System;
namespace AA.switchprotocol.UI