2010-06-04 20 views
2

我想我的應用程序,爲所有的網頁通過SSL的,所以我增加了線條...如何讓我的ASP.NET應用程序僅通過HTTPS提供頁面?

<secureWebPages enabled="true"> 
<directory path="." /> 
</secureWebPages> 

...我的Web.config文件和編譯器產生的錯誤是:

構建(網絡):無法識別的配置部分secureWebPages。

我在運行Visual Studio 2008

+0

的可能的複製http://stackoverflow.com/questions/2393114/how-to-secure-login-and -member-area-with-ssl-certificate – citronas 2010-06-04 18:03:21

+0

.NET框架的哪個版本是運行的站點? – 2010-06-04 18:09:50

回答

3

如果你想要一個簡單,快捷的解決方案,爲您的整個Web應用程序的工作,你可以在你的Global.asax文件中添加這到Application_BeginRequest方法。

Sub Application_BeginRequest(ByVal sender As Object, ByVal e As EventArgs) 
... 
    If Request.IsSecureConnection = False Then 
     Dim ub As New UriBuilder(Request.Url) 
     ub.Scheme = Uri.UriSchemeHttps 
     ub.Port = 443 
     Response.Redirect(ub.Uri.ToString, True) 
    End If 
... 
End Sub 
5

聽起來像是你可能需要添加相應的configSections ...

<configuration> 
    <configSections> 
    <!-- modify as you need. --> 
    <section 
     name="secureWebPages" 
     type="Hyper.Web.Security.SecureWebPageSectionHandler, 
     WebPageSecurity" 
     allowLocation="false" /> 
    </configSections> 


    <secureWebPages mode="On" > 
    <directories> 
     <add path="/" recurse="True" /> 
    </directories> 
</secureWebPages> 
相關問題