[英]ASP.NET Unicode string displays incorrectly
我有圖像:
http://localhost/WOZNIAK.png
這很好。 但是,如果我使用此規則重寫URL:
<rewrite url="~/images/articles/(.*)$" to="~/handlers/displayimage.ashx?src=$1&type=article" processing="stop"/>
並訪問此URL:
http://localhost/images/articles/WOZNIAK.png
它不顯示圖像。 我的處理程序以代碼開頭:
public void ProcessRequest (HttpContext context) {
string ImageSrc = context.Request.QueryString["src"];
string ImageType = context.Request.QueryString["type"];
如果我取ImageSrc
值,它輸出為:
WOŹNIAK.png
如果我將ImageSrc
顯式設置為值ImageSrc = "WOZNIAK.png";
在代碼中圖像顯示正常。
我需要做些什么才能讓這些Unicode字符正確傳遞? 這對我們來說是非常有問題的,因為我們讓世界各地的用戶上傳大量圖像,其中一些包含許多帶有Unicode字符的名稱。
由於設計的原因,以任何方式重命名或修改這些圖像都是非常有問題的,所以我真的想要解決這個問題!
編輯
看來我應該是Server.UrlEncode
所有查詢字符串參數。 這可能是原因嗎? 我不確定是否可以在URL重寫規則中執行此操作?
如果我將字符串設置為:
ImageSrc = context.Server.UrlDecode("WO%c5%b9NIAK.png");
有用。 所以我想問題是在重寫規則中編碼查詢字符串參數的URL。
我修好了它。 Intelligencia具有URL編碼變換,可以像下面一樣使用:
<rewrite url="~/images/articles/(.*)$" to="~/handlers/displayimage.ashx?src=${encode($1)}&type=article" processing="stop"/>
然后在代碼中顯示如下圖像:
string ImageSrc = context.Server.UrlDecode(context.Request.QueryString["src"]);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.