I’ve got a project where I’m tasked with changing hard-coded domain references from one domain to another in a group of legacy C#/VB web projects. I want to parameterize the domains as much as possible instead of just replacing with a different hard-coded value. The problem is that there are over 800 of these references in about 30 different solutions, so creating variables in each code-behind to bind to would take forever.
I have added the new domains to the appSettings section of the web.config file, and this works:
<asp:HyperLink Text="Link" NavigateUrl="<%$appSettings:DomainX %>" runat="server" />
But I need to be able to do something like this:
<asp:HyperLink Text="Link" NavigateUrl="<%$appSettings:DomainX %>/newPage.aspx" runat="server" />
But when I add the “/newPage.aspx” the page doesn’t compile anymore. I don’t really care if this is done with an asp:HyperLink tag or just a tag.
Any ideas on how I can accomplish this?
Thanks.
I think you have two options. The easiest is to just use a plain old anchor tag, if you’re not doing anything with the
HyperLinkserver side:Alternatively, you could set the
NavigateUrlin thePage_Load, since <%= will not work properly within theHyperLinkserver tag:You could also see if you can make a custom binding, something like
$myBinding:DomainX, but I don’t know if that’s possible off the top of my head (I would assume it is though).EDIT
That
$appSettings:DomainXcode is called an ASP.NET Expression, and can you can create custom expressions. This post from Phil Haack covers how to set them up, in case you are interested.