ASP.NET MVC Response Filter + OutputCache Attribute

前端 未结 2 1435
自闭症患者
自闭症患者 2021-01-13 04:45

I\'m not sure if this is an ASP.NET MVC specific thing or ASP.NET in general but here\'s what\'s happening. I have an action filter that removes whitespace by the use of a r

2条回答
  •  时光说笑
    2021-01-13 05:34

    AFAIK, the problem is that the action filters doesn't get executed if the request goes to the output cache. The AuthorizeAttribute works around this problem by calling some obscure Output Cache API. However, I don't think that is the best solution for what you're are trying to do.

    You should be working with output cache, not around it. What you should be doing instead is making sure that the spaces are removed from the response before it gets stored in the output cache.

    Update

    It seems that attaching a filter, no matter what filter, disables the WriteSubstitution functionality as you suspect. I've tried following the trail in the HttpResponse class using reflector but I can't find any proof that confirms this suspicion. I think the answer lies within the HttpWriter class.

    Another Update

    It so happens that I'm currently reading the excellent book "Pro ASP.NET MVC Framework" by Steve Sanderson (buy it if you don't already have it). In chapter 10 he links to a post on his blog where he talks about partial output caching and the poor integration between the MVC framework and the output cache. I haven't tried the custom outputcache attribute in the post yet... I will try it out and let you know if it does anything to solve the problem.

提交回复
热议问题