How to tell if code is running locally from Visual Studio/Cassini

Two ways I have done this 1 you can check the process name

bool isRunningInIisExpress = Process.GetCurrentProcess()
                                .ProcessName.ToLower().Contains("iisexpress");

Or update your config file with a custom setting

<appSettings>
    <add key="ApplicationEnvironment" value="LOCAL_DEV" />
</appSettings>

That you update specifically for each environment and have you application query for

I'm not sure if there is a way to determine this at compile time, besides having a special build configuration that is for each environment and putting a custom PRAGMA for each of these builds. Personally I think that is not as elegant, but it could also work.