我正在使用Request.IsSecureConnection檢查SSL並在適當的位置重定向。當在Rackspace的雲上運行我的asp.net網站時,服務器運行在SSL集羣后面,因此IsSecureConnection將始終返回false。檢查URL是否包含「https://」,始終爲false,檢查端口等等也是如此。因此,該網站被卡在大的重定向循環中。託管在Rackspace(Mosso)Cloud時檢查SSL
是否有其他方法檢查SSL並在適當的地方重定向?任何已經在Rackspace的雲端上實現了這一點的人?
Public Class SecurityAwarePage
Inherits Page
Private _requireSSL As Boolean = False
Public Property RequireSSL() As Boolean
Get
Return _requireSSL
End Get
Set(ByVal value As Boolean)
_requireSSL = value
End Set
End Property
Private ReadOnly Property IsSecure() As Boolean
Get
Return Request.IsSecureConnection
End Get
End Property
Protected Overrides Sub OnInit(ByVal e As System.EventArgs)
MyBase.OnInit(e)
PushSSL()
End Sub
Private Sub PushSSL()
Const SECURE As String = "https://"
Const UNSECURE As String = "http://"
If RequireSSL AndAlso Not IsSecure Then
Response.Redirect(Request.Url.ToString.Replace(UNSECURE, SECURE))
ElseIf Not RequireSSL AndAlso IsSecure Then
Response.Redirect(Request.Url.ToString.Replace(SECURE, UNSECURE))
End If
End Sub
End Class
不是說它與這個問題有什麼關係,但是你對於使用const的簡單字符串如'http'和'https'有很好的理解。 – 2011-12-03 19:46:31