0

I have a requirement only 100 request can serve per day in asp.net. Do we have any setting in asp.net so that i can control the incoming request to 100 per day?

tereško
  • 58,060
  • 25
  • 98
  • 150
  • 5
    Just interested: **why** would you want this? – Bas Jul 02 '14 at 13:18
  • Specifically, what is request in this context? Is it 100 requests total? 100 requests per user per day? 100 requests from 12 GMT to 23:59 GMT? Or over a rolling 24 hour period? In any case, you'll likely just need to implement a database and keep track of the requests in that. The `Application_BeginRequest` method in Global.asax may help you. – mason Jul 02 '14 at 13:19
  • 1
    Sounds like a pretty easy denial of service attach if your server shuts down after 100 requests. – paparazzo Jul 02 '14 at 13:30
  • Check This page you can find how to log incoming and right your own code to block @ 100 requests http://blogs.msdn.com/b/rodneyviana/archive/2014/02/06/logging-incoming-requests-and-responses-in-an-asp-net-or-wcf-application-in-compatibility-mode.aspx – Anto king Jul 02 '14 at 15:04

1 Answers1

0

The following post has code (from the actual codebase of StackOverFlow) which presents a simple and effective approach to 'throttling' requests.

This code is an action filter for ASP.NET MVC (you haven't indicated which flavor of ASP.NET you are using).

The code is using the Cache and cache expiration values to accomplish rejecting (throttling) a request if it has been issued more than once in a specified time period from a particular IP address.

You could easily change this code so that it rejects a request if has been issued more than 100 times in a specified time period (one day in your case).

In the sample code store a simple TRUE value is being stored in the Cache. You could change this to store an integer to represent the number of requests already served. Each time the filter executes you can increment increment this value and resave it in the cache (same expiration though). Check if this value >= your threshold to decide if the request should be rejected.

Hope that helps

Community
  • 1
  • 1
David Tansey
  • 5,813
  • 4
  • 35
  • 51