1

I want to block any request from some country regions.

How to do this in asp.net mvc?

xport
  • 6,925
  • 12
  • 48
  • 87
  • If I were in your place, I'd try to do that in app server settings, not the application itself. – Goran Jovic Dec 25 '10 at 17:36
  • I am using shared hosting account so I cannot touch the server. – xport Dec 25 '10 at 17:37
  • When implementing any suggested answer, I feel I should point out that a user could potentially get around pretty much any geographical restriction you place upon them with any number of solutions. One of the more popular solutions would be a proxy. – Dan Atkinson Dec 25 '10 at 23:05
  • @Dan, can we black-list the proxy addresses? How to know whether or not the incoming request from proxy servers? – xport Dec 26 '10 at 00:44
  • 1
    @xport. You've got no chance of doing either. There'll be too many proxies to blacklist, and users can simply create their own, and there's no way to distinguish the requests from a normal request. – Dan Atkinson Dec 26 '10 at 12:59
  • @Dan, thanks. I got the point. – xport Dec 26 '10 at 13:00

2 Answers2

2

You can define a HttpModule and then identify the origin of incoming request using one of the methods defined in this SO post to filter the requests

Community
  • 1
  • 1
Chandu
  • 78,650
  • 19
  • 129
  • 131
0

I'd recommend the MaxMind GeoCountry database, which is also the accepted answer for the post @Cybernate recommended. I personally use the paid Region database and am quite satisfied with it.

I'm not sure about going the route of an HttpModule however. I personally feel better with an ActionFilterAttribute which overrides the OnActionExecuting method.

Gup3rSuR4c
  • 8,748
  • 10
  • 65
  • 118