简体   繁体   中英

ASP.NET cache memory saving code

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 ?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM