Block IP List in ASP.NET Web Application / Website

I have a group of IP addresses.

After deploying my application, I want to have access only to my application from a specific IP address.

How can I achieve this using Global.asax (not through IIS)?

+5
source share
3 answers

This is a good starting point for you.

(especially since it is perfectly split into an HttpModule for later reuse)

+2
source

In the session start handler:

let's say that you have an array of blocked IP ie Code (text):

Dim bArr () As String = {"198.122.xxx.xx", "xxx.xxx.xx.xxx", etc.}

Code (text):

Dim strIP = Request.ServerVariables("HTTP_X_FORWARDED_FOR")
If strIP="" Then strIP = Request.ServerVariables("REMOTE_ADDR")

For i As integer = 0 To bArr.UperBound
  If strIP = bArr(i) Then
     Response.Redirect("Permissionsdenied.html")
  End If
Next
0
source

I would start this way, in the request start event handler in your global class, I would define the client IP address following this answer: fooobar.com/questions/24419 / ...

then if the ip connection is not in the allowed list, I would redirect to another page, such as the access denied page, the login page or the / google company home page.

0
source

All Articles