Is there any way to create an environment variable by IIS?

Asked

Viewed 333 times

0

I have an application running on local IIS and also in production. In this application, I have a feature where, when an error occurs, an email is sent. The problem is I don’t want that to happen when I’m in a development environment.

I thought about determining some environment variable to do this on IIS (but I want this variable to be specific to this application).

Is there any way to define specific environment variables for an application running on IIS?

  • 2

    have tried the web.config ?

  • I suggest using the debug mode option, and it is only enabled in the test environment: https://msdn.microsoft.com/pt-br/library/e8z01xdh.aspx

  • @Rovannlinhalis um... how would I do that? I’m really messing with C# and derivatives for a little while, all help is welcome.

  • I believe it is just to check, with an if: if(HttpContext.Current.IsDebuggingEnabled
)

  • @Rovannlinhalis but how will IIS know it is debug or not? That’s the question. You’re talking about that flag debug=true of compilation?

  • yes, I will elaborate an answer, but ask you to take a test. I have no way to test it now. If it goes wrong, let me know to remove ok ?

Show 1 more comment

1 answer

2


You can set in your web.config, on the tag compilation, the attribute debug:

In the development environment:

<configuration>  
    ...  
    <system.web>  
        <compilation  
            debug="true"  
            ...  
        >  
        ...  
        </compilation>  
    </system.web>  
</configuration>  

In the production environment:

<configuration>  
    ...  
    <system.web>  
        <compilation  
            debug="false"  
            ...  
        >  
        ...  
        </compilation>  
    </system.web>  
</configuration>  

Within the application, you check whether it is in debug mode, and upload:

if (!HttpContext.Current.IsDebuggingEnabled) 
{
    //envia o email
}
else
{
    //não envia email ou envia para outro endereço
}

References:

https://msdn.microsoft.com/pt-br/library/e8z01xdh.aspx https://stackoverflow.com/a/542896/4713574

Browser other questions tagged

You are not signed in. Login or sign up in order to post.