-3

In my Appcode folder as seen above I have a Class called BaseClass. In BaseClass I have a function called CheckWAN() that defines IP ranges so that later I can auto authenticate local users to my site via their IP address range.

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

Finally I have a set up a login on the site default.aspx that Checks the IP address of the user connecting if the If CheckWAN() returns true then I get passed along to the content page however if it is false then it shows me the login with a message that it is returning false

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

I have also checked with networking to verify the IP's used in my code and they all are valid.

Edited! here is what Request.UserHostAdress returns debug

Skullomania
  • 2,225
  • 2
  • 29
  • 65
  • are you sure there isnt something wrong in the code that your blanket Try/Catch (return false) is not firing? – Ňɏssa Pøngjǣrdenlarp Oct 24 '13 at 14:38
  • 1
    Are you sure that it is the else returning `False` and not that a exception is being thrown and the `False` inside the `catch` is being returned? – Scott Chamberlain Oct 24 '13 at 14:38
  • Check for exceptions using a stacktrace. – Jeroen Vannevel Oct 24 '13 at 14:39
  • 5
    Have you stepped through in debug mode? – ED-209 Oct 24 '13 at 14:39
  • @ScottChamberlain I have changed the final return to True and it still returned false. – Skullomania Oct 24 '13 at 14:42
  • 1
    What stops you from checking exact values you are working with? Print out `strRemoteAddress` (or enter debug and see its value). Most likely it will be 127.0.0.1 or something like that (if you are connecting to server on your local machine) – Viktor S. Oct 24 '13 at 14:43
  • Set a breakpoint and let us know if the Catch block is being triggered. – Douglas Barbin Oct 24 '13 at 14:43
  • 2
    you need to step through it, see what the value of strRemoteAddress is when it's running – ED-209 Oct 24 '13 at 14:43
  • Not part of your problem, but why do you declare a second variable, strRemoteAddress = to RemoteAddress when you never use RemoteAddress again and they are the same type? – nycdan Oct 24 '13 at 14:45
  • @whoshotjr I have ran through Debug mode to see if the Base Class Function was being checked at all and it is but its false – Skullomania Oct 24 '13 at 14:48
  • @nycdan remoteAddress is not being declared twice I am placing the value of the string `Request.UserHostAdress` into another variable – Skullomania Oct 24 '13 at 14:52
  • Right. You are putting into two variables but you never reference the first one after you set the second one to it. It seems unnecessary if the entire function is what you posted. – nycdan Oct 24 '13 at 15:41
  • From the image you posted, `Request.UserHostAddress` is `"::1"`. Please see http://stackoverflow.com/questions/1932843/iis-request-userhostaddress-returning-ipv6-1-even-when-ipv6-disabled for ideas. – Andrew Morton Oct 24 '13 at 19:03

1 Answers1

0

First of all, this should not even compile. Apparently it does, so you must have Option Strict Off. Request.UserHostAdress returns a complex object, and you declared your variable as a string. I suspect that what you actually want is some property of that object, although I don't know which one.

Douglas Barbin
  • 3,595
  • 2
  • 14
  • 34