asp.net 開發過程中關於image控制項中圖片點擊後地址亂碼的問題

來源:互聯網
上載者:User

標籤:style   color   檔案   資料   width   os   

前台頁面是這樣的:

<%-- 圖片展示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="width: 340px; height: 405px; vertical-align: top; border: 0;" id="imgTP_YYZZ" />
            </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);

問題無非就是請求或者返回時候編碼方式不對,寫代碼時候多加註意,出問題多加分析即可。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.