C# ASP.NET Unicode字符串显示不正确
我有这样的形象:C# ASP.NET Unicode字符串显示不正确,c#,asp.net,string,unicode,iis-7.5,C#,Asp.net,String,Unicode,Iis 7.5,我有这样的形象: http://localhost/WOZNIAK.png 结果很好。但是,如果我使用此规则重写此URL: <rewrite url="~/images/articles/(.*)$" to="~/handlers/displayimage.ashx?src=$1&type=article" processing="stop"/> 它没有显示图像。我的处理程序以以下代码开始: public void ProcessRequest (HttpCont
http://localhost/WOZNIAK.png
结果很好。但是,如果我使用此规则重写此URL:
<rewrite url="~/images/articles/(.*)$" to="~/handlers/displayimage.ashx?src=$1&type=article" processing="stop"/>
它没有显示图像。我的处理程序以以下代码开始:
public void ProcessRequest (HttpContext context) {
string ImageSrc = context.Request.QueryString["src"];
string ImageType = context.Request.QueryString["type"];
string ImageSrc = context.Server.UrlDecode(context.Request.QueryString["src"]);
如果我取ImageSrc
值,它输出为:
WOŹNIAK.png
如果我显式地将ImageSrc
设置为值ImageSrc=“WOZNIAK.png”代码>在代码中,图像显示良好
我需要做什么才能让这些Unicode字符正确地传递?这对我们来说是一个很大的问题,因为世界各地的用户都在上传大量的图像,其中一些图像包含许多带有Unicode字符的名称
由于设计原因,以任何方式重命名或修改这些图像都是非常有问题的,所以我真的很想解决这个问题
编辑
似乎我应该Server.UrlEncode
所有查询字符串参数。这可能是原因吗?我不确定在URL重写规则中是否可以这样做
如果我将字符串设置为:
ImageSrc = context.Server.UrlDecode("WO%c5%b9NIAK.png");
它起作用了。因此,我假设问题是在重写规则中对querystring参数进行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"]);