我正在使用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