在我上面看到的Appcode文件夾中,我有一個名爲BaseClass的類。在BaseClass中,我有一個名爲CheckWAN()的函數,它定義了IP範圍,以便稍後我可以通過它們的IP地址範圍自動向我的站點驗證本地用戶。爲什麼我的if else返回false?
Public Function CheckWAN() As Boolean
Try
Dim url As String = Request.Url.ToString()
'Get the client ip address
Dim RemoteAddress As String = Request.UserHostAddress
Dim strRemoteAddress As String = RemoteAddress
Dim myWAN As String = "192.168.254.254"
'add Some other ips
Dim SOther001 As String = "192.168.254.1"
Dim SOther002 As String = "192.168.254.2"
Dim SOther003 As String = "192.168.254.3"
If strRemoteAddress.Contains(myWAN) Then
Return True
ElseIf strRemoteAddress.Contains(SOther001) Then
Return True
ElseIf strRemoteAddress.Contains(SOther002) Then
Return True
ElseIf strRemoteAddress.Contains(SOther003) Then
Return True
Else
Return False
End If
Catch
Return False
End Try
End Function
最後我有一個建立在網站的Default.aspx,檢查連接,如果If CheckWAN()
返回true,則我融洽相處,從而但是內容頁傳遞的用戶的IP地址登錄,如果是假的,然後它讓我有一個消息,它返回假
Public Class BaseClass
Inherits System.Web.UI.Page
If CheckWAN() = True Then
Response.Redirect("/content.aspx")
Else
Response.Write("The CheckWAN is returning False")
'this else also causes a redirect loop if its changed to
'Response.Write(/default.aspx) not sure why
End If
我還檢查與聯網驗證登錄的IP在我的代碼中使用,它們都是有效的。
已編輯! 這裏是Request.UserHostAdress返回 debug
你確定代碼中沒有錯誤,你的覆蓋Try/Catch(return false)沒有被觸發嗎? – Plutonix
你確定它是否返回'False',而不是拋出異常並且'catch'內部的'False'被返回? –
使用堆棧跟蹤檢查異常。 –