Search code examples
asp.net-mvcweb-configoutputcachemedium-trust

Should OutputCacheProfiles (in webconfig) be accessible under a medium trust environment?


I'm trying to use DevTrends Donut Caching in an MVC app in a shared hosting environment.

When I upload the app I get this error:

System.Security.SecurityException: MvcDonutCaching does not have permission to read web.config section 'OutputCacheSettingsSection'.

The host provider says that this restriction is due to the Medium Trust environment.

While I am not knowledgable enough to argue with this, it seems strange / unreasonable that basic Web.Config settings are unavailable under medium trust.

Plus, at the bottom of this workitem, from 2012, the author states that:

I have added some code to allow MvcDonutCaching to be used in a strict Medium Trust environment

Should I be able to access these settings in a medium trust environment?

The caching settings that I am using in web.config are like this:

  <system.web>
    <caching>
      <outputCacheSettings>
        <outputCacheProfiles>
          <add name="CacheFor1Hour" duration="3600" varyByParam="none" />
          <add name="RecacheOnUpdate" duration="2419200" varyByParam="*" />
          <add name="Dashboard" duration="86400" varyByParam="*" varyByCustom="User" location="Server" />
        </outputCacheProfiles>
      </outputCacheSettings>
    </caching>
  </system.web>

Solution

  • Ok I found the answer here: http://mvcdonutcaching.codeplex.com/workitem/2466

    So it looks like you just can't do it in a strict Medium Trust environment. I wish my hosting company were like "most hosting companies" in the quote below... :-(

    Thank you for the comprehensive description. I have tracked down the problem. Because you have a strict medium trust environment, MvcDonutCaching cannot access the ConfigurationSection from the web.config that stores cache profiles. I have improved the code to provide a meaningful error message, but without that permission, it is not possible to use cache profiles. Most hosting environments modify the Medium trust settings to allow access to configuration sections, so if you own the server, this is one option open to you. Otherwise, to use MvcDonutCaching, you will need to avoid cache profiles and add duration to the attribute itself.