Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Niels Lyngsø 21 posts 99 karma points hq
    Apr 04, 2017 @ 08:24
    Niels Lyngsø
    0

    Test wether a env. is running with debug mode?

    Hello

    I would love to be able to determine wether a site is running in DEBUG mode or not. Is there anyway to check this?

    Here is an example that hopefully shows the general idea:

    if (umbracoDebugMode == true) {
        @Html.Raw("app.js");
    } else {
        @Html.Raw("app.min.js");
    }
    

    Thanks

  • Alex Skrypnyk 6163 posts 24143 karma points MVP 8x admin c-trib
    Apr 04, 2017 @ 09:54
    Alex Skrypnyk
    1

    Hi Niels

    Of course you can do it.

    I don't know internal method for it, but you can do it like:

    if (bool.Parse(ConfigurationManager.AppSettings["umbracoDebugMode"]) == true) {
    @Html.Raw("app.js");
    } else {
    @Html.Raw("app.min.js");
    }
    

    Thanks,

    Alex

  • Alex Skrypnyk 6163 posts 24143 karma points MVP 8x admin c-trib
    Apr 04, 2017 @ 09:56
    Alex Skrypnyk
    101

    Another way is to use System.Diagnostics, something like:

    NameSpace:

    using System.Resources;
    using System.Diagnostics;
    

    Method:

    private static bool IsDebug()
        {
            object[] customAttributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(DebuggableAttribute), false);
            if ((customAttributes != null) && (customAttributes.Length == 1))
            {
                DebuggableAttribute attribute = customAttributes[0] as DebuggableAttribute;
                return (attribute.IsJITOptimizerDisabled && attribute.IsJITTrackingEnabled);
            }
            return false;
        }
    
Please Sign in or register to post replies

Write your reply to:

Draft