[Webinar] Streamline your web hosting managementRegister Today

x
?
Solved

asp.net put base url in web.config file

Posted on 2008-02-07
5
Medium Priority
?
2,620 Views
Last Modified: 2012-06-27
I want to put my base url in an web.config file, then use it in a link so I can change the url when I deploy.  How do I do that?

This does not work:
                        <asp:HyperLink ID="OpportunitySearchLink" runat="server"
                            NavigateUrl="<%=ConfigurationSettings.AppSettings["baseURL"] %>OpportunitySearch.aspx">Opportunity Search</asp:HyperLink><br />
0
Comment
Question by:jackjohnson44
  • 3
5 Comments
 
LVL 9

Expert Comment

by:zkeown
ID: 20843145
I think you just need a slight modification:

NavigateUrl='<%=ConfigurationSettings.AppSettings["baseURL"] & "OpportunitySearch.aspx" %>'

Note the single quotes around the entire NavigateURL property
0
 
LVL 15

Expert Comment

by:OMC2000
ID: 20843166
put entry like the following to web.config
      <appSettings>
            <add key="baseURL " value="/Portal" />

make sure that baseURL key in the web.config is terminated with slash or add it before OpportunitySearch.aspx:

%>/OpportunitySearch.aspx"
0
 

Author Comment

by:jackjohnson44
ID: 20843371
Thanks, but that didn't exactly work.  I can get the url to print correctly, but when it is in a tag, it isn't getting displayed correctly.  Meaning when I print it above the link, it looks good.  I think it is the single quote

Here is the code:
<asp:HyperLink ID="OpportunitySearchLink" runat="server"
                            NavigateUrl='<%=ConfigurationManager.AppSettings("baseurl") & "OpportunitySearch.aspx" %>'>Opportunity Search</asp:HyperLink><br />

Here is how it displays when I view source:
<a id="OpportunitySearchLink" href="&lt;%=ConfigurationManager.AppSettings(&quot;baseurl&quot;)%20&amp;%20&quot;OpportunitySearch.aspx&quot;%20%>">Opportunity Search</a><br />
0
 
LVL 15

Expert Comment

by:OMC2000
ID: 20843603
ups, you cannot use servers side code inside ASP.NET tags. You could assign value to the property
NavigateUrl  of OpportunitySearchLink like the following


<%
OpportunitySearchLink.NavigateUrl = RosReg.ASPZ.Common.WebRoot + "/OpportunitySearch.aspx";
%>
<asp:HyperLink ID="OpportunitySearchLink" runat="server"
                            NavigateUrl=''>Opportunity Search</asp:HyperLink><br />
0
 
LVL 15

Accepted Solution

by:
OMC2000 earned 2000 total points
ID: 20843610
sorry like this:

<%
OpportunitySearchLink.NavigateUrl = ConfigurationManager.AppSettings("baseurl")+ "/OpportunitySearch.aspx";
%>
<asp:HyperLink ID="OpportunitySearchLink" runat="server"
                            NavigateUrl=''>Opportunity Search</asp:HyperLink><br />
0

Featured Post

[Webinar] Improve your customer journey

A positive customer journey is important in attracting and retaining business. To improve this experience, you can use Google Maps APIs to increase checkout conversions, boost user engagement, and optimize order fulfillment. Learn how in this webinar presented by Dito.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Enter Foreign and Special Characters Enter characters you can't find on a keyboard using its ASCII code ... and learn how to make a handy reference for yourself using Excel ~ Use these codes in any Windows application! ... whether it is a Micr…
Stellar Phoenix SQL Database Repair software easily fixes the suspect mode issue of SQL Server database. It is a simple process to bring the database from suspect mode to normal mode. Check out the video and fix the SQL database suspect mode problem.
Suggested Courses

590 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question