The best way to find out if it works in a .NET development or development environment.

I would like to send emails in different ways, and then to the development environment, such as sending emails only to me during testing. I know that I can set the application value in the webconfig file or check the URL before sending emails. I would like to know what works best for this, or if there is some other option that I don't know about, what could be better? Any information on this topic would be greatly appreciated.

+5
source share
4 answers

I use what is called the Preprocessor Directives (in C #) . In VB, it is called Directive Only .

I have a helper method:

public static bool IsDebug()
{
    #if DEBUG
        return true;
    #else
        return false;
    #endif
}

Then, anywhere in the code, you can call this method at runtime, and it will tell whether the code is being executed in Debug(development), or if it is version Release(production).

Here is the equivalent of # If ... Then ... # Else Directives in (VB).

+3
source

Instead of changing the code, why don't you configure the development mail server to send you only messages regardless of the TO address field?

It seems better to write code for this.

+1
source

, , , web.config , , (DI) ala Spring.Net, StructureMap Castle Windsor, .

DI / , . , , "mail" ( , prod dev environment), DI , mail. , .

, , , , - .

+1

- IIS, , .

, .NET(, /inetpub/wwwroot.web.config web.config(\Windows\Microsoft.NET\Framework\ver\web.config)), ,

PROD

  <appSettings>
    <add key="sendMailTo" value="" />
    <add key="environmentName" value="PROD" />
  </appSettings>

DEV

  <appSettings>
    <add key="sendMailTo" value="me@mydomain.com" />
    <add key="environmentName" value="DEV" />
  </appSettings>

. , , , .

+1

All Articles