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

时间:2019-04-01 13:03:13   收藏:0   阅读:1318

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

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

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!