2014-12-23 87 views
0

我有簡單的腳本,我保存新聞細節,如News Title, News URL and News Image URL。我注意到,圖像時它已Unicode字符就拿不顯示http://www.bbj.hu/images2/201412/párizsi_ud_20141218113410452.jpgHTMLEncodes圖片URL和打破圖像

它存儲在數據庫中,因爲它是,但是當我在網頁符顯示它&顯示爲 http://www.bbj.hu/images2/201412/pa%c2%b4rizsi_ud_20141218113410452.jpg

當我調試我的asp.net Web窗體頁在代碼中正確顯示背後

protected String getImage(object imgSource) 
    { 
     string img = null; 
     img = imgSource.ToString(); 
     return img; 

//調試顯示圖像的URL正確,但它打破了實際的頁面 }

的.aspx代碼

<asp:Image ID="NewsImage" ImageUrl='<%# getImage(Eval("NewsImageURL")) %>' runat="server" /> 

我嘗試不同的東西,但它一直顯示爲http://www.bbj.hu/images2/201412/pa%c2%b4rizsi_ud_20141218113410452.jpg

我怎樣才能解決這個

回答

0

你的問題的解決方案必須是一個或多個以下的中:

C#URL編碼/解碼:

string encodedUrl = HttpUtility.UrlEncode(myUrl); 
string sameMyUrl = HttpUtility.UrlDecode(encodedUrl); 

JavaScript網址編碼/解碼:

function myFunction() { 
    var uri = myUrl; 
    var uri_enc = encodeURIComponent(uri); 
    var uri_dec = decodeURIComponent(uri_enc); 
} 

C#HTML編碼/解碼:

string encodedHtml = HttpUtility.HtmlEncode(myHtml); 
string sameMyHtml = HttpUtility.HtmlDecode(encodedHtml); 

的JavaScript的HTML編碼/解碼:

function htmlEncode(value) { 
    //create a in-memory div, set its inner text (which jQuery automatically encodes) 
    //then grab the encoded contents back out. The div never exists on the page. 
    return $('<div/>').text(value).html(); 
} 

function htmlDecode(html) { 
    return $('<div>').html(html).text(); 
}