0

My application has to use a CDN in production. We don't want to use the same CDN in development and production. How and where can I define a property "CDN_URL" for each build profile so that it is substituted at buid time or retrieved dynamically at runtime.

I'd like to write something like:

<link rel="stylesheet" type="text/css" href="${CDN_URL}/styles/base.css" />
mvera
  • 904
  • 12
  • 23

1 Answers1

2

You will want to store the CDN URL in the app settings in the web.config.

For example:

<appSettings>
    <add key="Live_CDNURL" value="http://live.cdn.com"/>
    <add key="Development_CDNURL" value="http://dev.cdn.com"/>
</appSettings>

Then in the application you can use:

 WebConfigurationManager.AppSettings["Live_CDNURL"];

Then simply add the stylesheet using asp following something like Adding StyleSheets Programmatically in Asp.Net

Or do:

<link rel="stylesheet" type="text/css" href="<%=ConfigurationManager.AppSettings("Live_CDNURL")%>/styles/base.css" />
Community
  • 1
  • 1
Ryan McDonough
  • 9,732
  • 3
  • 55
  • 76
  • thanks you explained me how to use a property from web.config in an ASP page. But how can I use a single property "CDNURL" and change its value depending on my deployment platform ? – mvera Sep 30 '14 at 12:16
  • Well you can store just CDNURL in the web.config - you will have on web.config used in dev and a separate web.config used in live. – Ryan McDonough Sep 30 '14 at 14:21