Content-Disposition 響應頭,設置文件在瀏覽器打開還是下載


Content-Disposition屬性有兩種類型:inline 和 attachment

inline :將文件內容直接顯示在頁面

attachment:彈出對話框讓用戶下載

code:

  context.Response.ContentType = "text/plain";
        string fileName = context.Request["fileName"];
        if(fileName!=null)
        {
            context.Response.AddHeader("Content-Disposition", "attachment;filename="+fileName);
            context.Response.WriteFile("downLoad/" + fileName);
        }


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM