asp.net 开发过程中关于image控件中图片点击后地址乱码的问题

前台页面是这样的:

<%-- 图片展示20140705add --%>
    <div id="imgShowDiv" style="left:550px; top:90px; height:430px; display:none;" class="msgboxStyle">
        <h1 onmousedown="startDrag(this)" onmousemove="drag(this)" onmouseup="stopDrag(this)" style="height: 29px;">
            <a id="A1" onclick="closeDlg(this)" href="#" class="iclose" title="关闭或隐藏"></a>
        </h1>
        <div style="top:30px; position:absolute;">
            <a href="" target="_blank" id="aTP_YYZZ">
                <img src="" class="jqzoom" style=" 340px; height: 405px; vertical-align: top; border: 0;" id="imgTP_YYZZ" alt="" />
            </a>
        </div>
    </div>

关联的js为:drag_layer.js和ImgShowFuncs.js,另外还要引用一个imagezoom.css的样式文件

点击图片时候新页面打开原图但是路径会报错,于是我在pageload中添加了第一句话解决之:

   Request.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");
        string args = Request.Params["args"].ToString();
        string imgPath = args;
        System.IO.FileStream aFile = new System.IO.FileStream(imgPath, System.IO.FileMode.Open, System.IO.FileAccess.Read);
        // 创建一个二进制数据流读入器,和打开的文件关联
        System.IO.BinaryReader brMyfile = new System.IO.BinaryReader(aFile);
        // 把文件指针重新定位到文件的开始
        brMyfile.BaseStream.Seek(0, System.IO.SeekOrigin.Begin);
        // 获取照片的字节数组
        byte[] photo = brMyfile.ReadBytes(Convert.ToInt32(aFile.Length.ToString()));
        // 关闭以上new的各个对象
        brMyfile.Close();
        Response.BinaryWrite(photo);

问题无非就是请求或者返回时候编码方式不对,写代码时候多加注意,出问题多加分析即可。

原文地址:https://www.cnblogs.com/thsgar/p/3831609.html