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

posted @ 2019-04-01 11:56  二狗狗狗狗狗  阅读(2201)  评论(0编辑  收藏  举报