Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 577613
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T14:10:20+00:00 2026-05-13T14:10:20+00:00

My actions in ASP.NET MVC controller are decorated with numerous properties like this [OutputCache(Duration

  • 0

My actions in ASP.NET MVC controller are decorated with numerous properties like this

    [OutputCache(Duration = 86400, Location = OutputCacheLocation.Client,
        VaryByParam = "jsPath;ServerHost")]
    [CompressFilter]
    public JavaScriptResult GetPendingJavaScript(string jsPath, string serverHost)

What I would like to do is to wrap this in something like #if and #endif, and have DebugMode setting in my web.config file. When this setting would be set to true, the decorating properties should be disregarded – I want to enable debug mode and in debug mode no compression and caching should occur.

So essentially it would be like commenting out those decorating properties (what I’m actually doing now and got fed up with it):

    //[OutputCache(Duration = 86400, Location = OutputCacheLocation.Client,
    //    VaryByParam = "jsPath;ServerHost")]
    //[CompressFilter]

Obviously #if and #endif work with defined (#define) C# symbols, I couldn’t find any example where this would work with other types of condition (like web.config values, etc.).

Help appreciated

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T14:10:20+00:00Added an answer on May 13, 2026 at 2:10 pm

    Instead of this, I would make use of Web Deployment Projects, and the configSource attribute in the web.config.

    I would split the web.config into two files for each component. For example, for your output cache would be split into outputcache.dev.config and outputcache.live.config. You should enter the config source as the dev config file.

    Your dev.config would basically tell your app that you don’t want to cache running (enableOutputCache="false").

    Then, when you run your deployment project, you can have settings to replace the dev.config strings with live.config instead.

    More discussion on configSource and Web Deployment Projects.

    As for your CompressFilter problem… Well, I would simply have an app setting value in your config files. Following on from splitting the config files, you would have appsettings.dev.config, and appsettings.live.config. In your dev, you would have something like:

    <add key="InLiveMode" value="false" />
    

    And in your live.config, yep, you’ve guessed it:

    <add key="InLiveMode" value="true" />
    

    Then when you use the attribute, you can simply against the InLiveMode app setting.

    FYI: I much prefer having some sort of facade class so I’m not dealing with magic strings in the code, but for the sake of simplicity, you’d have something like:

    //CompressFilter class
    public override void OnActionExecuting(ActionExecutingContext filterContext)
    {
      bool inLiveMode = bool.Parse(ConfigurationManager.AppSettings["InLiveMode"]);
    
      if(inLiveMode)
      {
        //Do the compression shiznit
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an ASP.NET MVC application using Authorization Attributes on Controllers and Actions. This
I would like to cache my most database heavy actions in my asp.net-mvc site.
The default controller in my ASP.NET MVC project is decorated with the [Authorize] attribute.
I'm trying to use F# for an ASP.NET MVC application. One my controller actions
I have an ASP.NET MVC web app and in one of the controller actions
In ASP.NET MVC, we have @Url.Action for actions. Is there something similar like @Url.Api
I'd like to achieve the following (with ASP.NET MVC 3): A controller called apps
I've looked at ASP.Net MVC routing legacy URLs passing querystring Ids to controller actions
When adding a controller in ASP.Net MVC 3 using Controller with Read/Write actions and
How does MVC asp.net serialization work for Json object on Controller actions ? For

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.