We have an app that allows users from both within the organization or outside.
However, if the user is from our organization, we would like to authenticate the user's account using our Active Directory.
If the user is coming from outside, we would like the user to register to obtain an acount.
We felt that the easiest way to handle this is to track their ip addresses from the subnet of their networks.
This seems simple enough but when I tried running the code below, it is continously showing the screen that is intended for outside users.
What am I doing wrong?
'//relevant markup:
<table bgcolor="#003366" width="100%">
<tr><td align="right"><asp:Panel id="pnlLoggedOut" runat="server" Visible="True">
<a href="login.aspx"><span style="color:#FF8C00;font-weight:bold">Login or Register</span></a>
</asp:Panel>
<asp:Panel id="Panel2" runat="server" Visible="False">
<a href="login.aspx"><span style="color:#FF8C00;font-weight:bold">Login</span></a>
</asp:Panel>
<asp:Panel id="pnlLoggedIn" runat="server" Visible="False">
<asp:Label ID="userLB" runat="server" ForeColor="#CC0000"></asp:Label><a href="logout.aspx"><span style="color:#ffffff;font-weight:bold">[Logout]</span></a>
</asp:Panel></td></tr></table>
'//relevant codeBehind:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
'Create a variable to hold your IP address.
Dim ipAddress As String = ""
'Retrieve the user's ip address from Page_Load():
ipAddress = Request.ServerVariables("REMOTE_ADDR")
'Then compare the retrieved IP address to the subnet for our network which is usually " 255.255.255.0".
If ipAddress.Contains(" 255.255.255.0") Then
pnlLoggedOut.Visible = False
Panel2.Visible = True
Else
pnlLoggedOut.Visible = True
Panel2.Visible = False
End If
'Response.Write(Session("UserRole"))
If Session("UserName") Is Nothing Or Session("UserName") = "" Then
pnlLoggedOut.Visible = True
pnlLoggedIn.Visible = False
Else
pnlLoggedIn.Visible = True
pnlLoggedOut.Visible = False
userLB.Text = "You are logged in as " & Session("FullName")
userLB.ForeColor = System.Drawing.Color.DarkOrange
End If
End Sub