Can I restrict IIS to run release code only

The company I work for has 2 servers, 1 release and 1 test/debug server. I want to restrict the release server that only code that is compiled as release (not having the DEBUG constant defined) can be run.

Is this possible and if so, how can I achive this? Can I set this in IIS or in the web.config?


There is no difference in the compiled assemblies when you compile with one flag versus another. The names "Debug" and "Release" are purely conventional. The setting I assume you are concerned about is whether the code is optimized or not. That too is not detectable.

Instead, as @HABO suggested, the answer would be to define a flag, present on developer's machines, which makes debug code acceptable. You could use something as simple as the following:

static class AssertProductionOptimized
    private static bool checkCompleted = false;
    private static bool isDeveloper = false;

    private const string regPath = @"Software\My Awesome Software, Inc";
    private const string regValue = "IsDeveloper";

    public static void AssertOptimized()
        if (checkCompleted)
            isDeveloper = checkIfDeveloper();
            checkCompleted = true;

        if (!isDeveloper)
            throw new InvalidOperationException(string.Format("Debug code running "
                + "on non-developer machine.  Either build without DEBUG flag, or "
                + "add a DWORD named {1} with a value of 1 to HKLM\\{0}",
                regPath, regValue));

    private static void checkIfDeveloper()
        RegistryKey hkKey = null;
            hkKey = Registry.LocalMachine.OpenSubKey(regPath);

            // if the key does not exist, we are not a developer
            if (hkKey == null)
                return false;

            var hkValueObj = hkKey.GetValue(regValue);

            return object.Equals(hkValueObj, 1);
        catch (Exception ex)
            throw new Exception("Exception occurred while checking developer status", ex);
            if (hkKey != null)

Category: iis Time: 2013-08-17 Views: 1
Tags: windows iis

Related post

iOS development

Android development

Python development

JAVA development

Development language

PHP development

Ruby development


Front-end development


development tools

Open Platform

Javascript development

.NET development

cloud computing


Copyright (C), All Rights Reserved.

processed in 0.276 (s). 12 q(s)