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