0

Just wondering if this is even doable. I've got 3 environments for a C#/ASP.Net project I'm working on; Development, Staging and Production. One recent development is that my users want a link to an outside reporting app. The reporting app also has 3 environments, so every time I copy the C#/ASP out to one of those servers, I have to remember to change the links.

So, imagine a hyperlink that looks like this:

<asp:HyperLink id="ReportLink" ForeColor="Snow" NavigateUrl="https://d-mysite.com/cgi-bin/rpt.dll?b_action=Viewer" Text="Go To My Reports" Target="_new" runat="server"/>

After it's tested in Development, I have to remember to change the URL to https://s-mysite.com before I publish to Staging, and then https://p-mysite.com before I publish to Production.

Is there any way to determine which server it's running off of, so that I can use an IF statement to determine which link to use?

Johnny Bones
  • 8,786
  • 7
  • 52
  • 117
  • this may be better. http://stackoverflow.com/questions/305447/using-different-web-config-in-development-and-production-environment – Adam Heeg Jul 30 '15 at 18:01

1 Answers1

0

Store the server name as an app setting in your web config, then refer to it in your code. You can have a transform set up to change the server name for each environment.

In your web.config:

<appSettings>
    <add key="Server" value="https://d-mysite.com" />
</appSettings>

Your link:

<asp:HyperLink id="ReportLink" ForeColor="Snow" NavigateUrl="<%$ AppSettings:Server %>/cgi-bin/rpt.dll?b_action=Viewer" Text="Go To My Reports" Target="_new" runat="server"/>
christophano
  • 915
  • 2
  • 20
  • 29