一:什么是https
SSL(Security Socket Layer)全稱是加密套接字協議層,它位於HTTP協議層和TCP協議層之間,用於建立用戶與服務器之間的加密通信,確保所傳遞信息的安全性,同時SSL安全機制是依靠數字證書來實現的。
SSL基於公用密鑰和私人密鑰,用戶使用公用密鑰來加密數據,但解密數據必須使用相應的私人密鑰。使用SSL安全機制的通信過程如下:用戶與IIS服務器建立連接后,服務器會把數字證書與公用密鑰發送給用戶,用戶端生成會話密鑰,並用公共密鑰對會話密鑰進行加密,然后傳遞給服務器,服務器端用私人密鑰進行解密,這樣,用戶端和服務器端就建立了一條安全通道,只有SSL允許的用戶才能與IIS服務器進行通信。
提示:SSL網站不同於一般的Web站點,它使用的是“HTTPS”協議,而不是普通的“HTTP”協議。因此它的URL(統一資源定位器)格式為“https://網站域名”。
二:https的本地測試環境搭建
1:win7/windows server 2008R2中 IIS7/IIS7.5 搭配https本地測試環境
2:windows server 2003中IIS6.0 搭配https本地測試環境
三:asp.net 結合 https的代碼實現
https是由IIS,瀏覽器來實現的傳輸層加密,不需要特意的編碼。。。平時怎么在asp.net里面編寫代碼,就怎么寫。
很可能要問,為什么我的站點使用了https之后,用firebug之類的軟件查看值提交的時候,還是會顯示明文呢?例如,博客園的登陸界面提交。
四:http網站轉換成https網站之后遇到的問題
整站https還是個別的頁面采用https?網站的連接是使用相對路徑?還是絕對路徑?
如果是整站都是https,那么會顯得網頁有些慢,如果是個別頁面采用https,那么如何保證從https轉換到http的時候的url的准確性呢?
比如我們用http的時候,網站的頭部底部都是用的相對路徑,假如你的頁面是 http://aa/index.aspx 你跳轉到 https://aa/login.aspx 這里怎么來跳轉?只能把超鏈接寫死
登陸 但是這樣的話,你跳轉過去之后的頁面 ,所有的相對路徑都變成了https開頭了,這樣很影響網站的效率。
解決辦法
下面就是使用第三方的組件,來解決上面的這個問題
http://www.codeproject.com/Articles/7206/Switching-Between-HTTP-and-HTTPS-Automatically-Ver
步驟 先下載dll文件 http://code.google.com/p/securityswitch/downloads/list 我選擇的是 SecuritySwitch v4.2.0.0 - Binary.zip這個版本
1.項目中添加引用 該dll
2.添加xsd文件
3.修改配置文件,控制https和http訪問的路徑
<paths>節點下的是通過https訪問的頁面,其他的是http路徑訪問的頁面
<configuration> <configSections> <section name="securitySwitch" type="SecuritySwitch.Configuration.Settings, SecuritySwitch"/> </configSections> <system.web> <compilation debug="true" targetFramework="4.5.2" /> <httpRuntime targetFramework="4.5.2" /> <httpModules> <!--配置securitySwitch,for IIS <= 6.x, IIS 7.x + 經典模式, and Web Development Server (Cassini) --> <add name="SecuritySwitch" type="SecuritySwitch.SecuritySwitchModule, SecuritySwitch" /> </httpModules> </system.web> <!--配置securitySwitch--> <securitySwitch baseInsecureUri="http://localhost/" baseSecureUri="https://localhost/" bypassSecurityWarning="true" ignoreAjaxRequests="false"> <paths> <add path="~/order.aspx"/> <add path="~/admin/Login.aspx" /> <add path="~/admin/userinfo.aspx" /> <add path="~/admin" /> </paths> </securitySwitch> <system.webServer> <validation validateIntegratedModeConfiguration="false" /> <modules> <!--配置securitySwitch,如果是 IIS 7.x + 集成模式 --> <add name="SecuritySwitch" type="SecuritySwitch.SecuritySwitchModule, SecuritySwitch" /> </modules> </system.webServer> </configuration>