2013-10-04 29 views
1

我有一個在Web.Release.config和Web.Debug.config中爲url定義的鍵值對。 在我使用它像C#的文件,所以(關鍵是「報告-URL」):請參閱ascx中的鍵值

string reportUrl = System.Configuration.ConfigurationManager.AppSettings["Report-URL"]; 
CoverSheetReportViewer.ServerReport.ReportServerUrl = new Uri(reportUrl); 

這工作,但現在我想在我目前擁有的網址硬編碼一個.ascx文件使用它:

<asp:HyperLink ID="HyperLinkReports" runat="server" CssClass="LeftNav" 
NavigateUrl="http://mygroup-dev-appsr/ReportServer?%2fASD%2fTransactions%2fCoverSheet&rs:Command=ListChildren" /> 

我該怎麼做?

回答

3

在.ascx.cs與Inline Syntax

NavigateUrl="<%$ AppSettings:Report-URL %> 

幫助試試這個在的.ascx

<a href="<%# this.GetReportUrl() %>">Report</a> 

protected string GetReportUrl(){ 
string reportUrl = System.Configuration.ConfigurationManager 
        .AppSettings["Report-URL"]; 

return new Uri(reportUrl).ToString(); 
} 

Another Syntax Reference

+0

我得到一個HTTP 400錯誤,但我是比你的例子有點不同,因爲我沒有HREF。 '」 –

+0

@mickey,當您懸停在鏈接上時看到的網址是什麼?它是爲您的網站生成的有效網址? –

+0

它可能不會調用該方法。瀏覽器中顯示的URL(在400錯誤時):http:// localhost:39536/Admin/Components /%3C%25 = this.GetReportUrl()%20%25%3E –