How not cache an ASP.NET user control?

后端 未结 3 1977
無奈伤痛
無奈伤痛 2021-01-02 23:15

I\'m using OutputCache in my page that has a user control, but I don\'t want to cache this specific user control because it\'s related to a user login (if I access the page,

3条回答
  •  佛祖请我去吃肉
    2021-01-03 00:13

    You can cache a page and you can cache a user control, but you can't cache a page except for a user control. When the user control runs the entire page has to run. You have to make the output cache for the page recognise the different users.

    You can use VaryByHeader="Cookie" to cache the page for each set of cookies if the user identity is stored in a cookie. You can use VaryByCustom="SomeString" and implement a check for SomeString to do your own check for user identity in the GetVaryByCustomString method in Global.asax.

提交回复
热议问题