SteveGSD
SteveGSD

Reputation: 1750

Is it possible to use ASP.Net web config app setting values as compiled constants?

I have some web config app settings like page urls that change based on development environment and production environment.

I'd like the app settings to be embedded in some aspx files somehow during compile time without having to call the app settings from code to make sure they are using the correct page urls.

Is this possible to do?

Upvotes: 2

Views: 442

Answers (1)

Aristos
Aristos

Reputation: 66641

Yes, you can use the compiler options to define your flags as:

<system.codedom>
<compilers>
  <compiler language="c#;cs;csharp" extension=".cs"   
   compilerOptions="/D:FirstDefine,SecondDefine" 
            type="Microsoft.CSharp.CSharpCodeProvider, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" warningLevel="4">
    <providerOption name="CompilerVersion" value="v4.0" />
    <providerOption name="WarnAsError" value="false" />
  </compiler>
</compilers>
</system.codedom>

Then on your code you can use

#if FirstDefine
     // ... your code 
#endif

MSDN Reference

C# Compiler Options Listed Alphabetically

Upvotes: 3

Related Questions