首页 > 其他 > 详细

Content-Disposition 响应头,设置文件在浏览器打开还是下载

时间:2019-04-01 13:03:13      阅读:1314      评论:0      收藏:0      [点我收藏+]

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);
        }

Content-Disposition 响应头,设置文件在浏览器打开还是下载

原文:https://www.cnblogs.com/ergougougou/p/10635569.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!