Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I am trying to create a site view counter for my ASP.NET-4.0 MVC-4 website. For this, what I am doing is:

I am storing the User's IP address in asp.net cache. And when the cache expired, I will do a bulk entry in my SQL Server Database.

Now for this I have to write a code which will insert the user's IP address in the cache memory. Initially I decided to write that code in my /Home/Index Action but then I thought if user visit my website's contact page directly and than leave my website without going to my website's home page then that user's IP address will not record in cache memory.

Now the obvious solution for this problem is that we can write a function and put a call to that function in My home and contact action and every other action. But I want something by which we can avoid writing function call at every place.

Can anybody please suggest me a good solution for this ?

share|improve this question
 
Create BaseController and derive all Controller from BaseController. –  Jeet Bhatt Jul 25 at 10:29

1 Answer

I think you mean "cache", not "catch"?

I also think you want one place that runs on every request, instead of having to put code in every controller.

In that case, you should look at adding to your Global.asax an event for Application_BeginRequest.

share|improve this answer
 
thanks and sorry for typo, when we deploy our website on server than also for every request to the website runs the Global.asax event ? –  user1740381 Jul 25 at 10:30
 
Correct - each managed request will also run the Application_BeginRequest method. –  pattermeister Jul 25 at 10:35

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.