user2906155
user2906155

Reputation: 21

How to cache the action in asp.net mvc on the basis of viewdata ? c#

I am passing the viewdata from base controller. Every controller is inherited from that controller class.

viewdata["currentuser"] is different for every kind of user.

How I can cached it differently for every different value of currentuser in viewdata.

Someone show me code through the ACtionfilter.

What I have tried ?

  1. I tried to add the cache through the this.httpcontext but it didn't return the viewdata back to me when I do this inside the controller action.

  2. I still stuck with the code that I can put on filter to cache the stuff.

Upvotes: 0

Views: 97

Answers (1)

user2906155
user2906155

Reputation: 21

What I am trying to do is serve different-different html response to every registered user. all guest user will got same response (guest user Id = 0 in all cases).

Outputcache is little bit hard. Because I need to check the current user before cache it.

Simply I do system.web.caching.insert this trick fix my problem.

Upvotes: 0

Related Questions