当前位置: 代码迷 >> 综合 >> Content-Disposition 响应头,设置文件在浏览器打开还是下载
  详细解决方案

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

热度:10   发布时间:2024-02-28 16:33:15.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);
        }

  相关解决方案