zoukankan      html  css  js  c++  java
  • C# 一般处理程序下载文件

    using System;
    using System.Collections;
    using System.Data;
    using System.Linq;
    using System.Web;
    using System.Web.Services;
    using System.Web.Services.Protocols;
    using System.Xml.Linq;
    
    namespace test
    {
        /// <summary>
        /// $codebehindclassname$ 的摘要说明
        /// </summary>
        [WebService(Namespace = "http://tempuri.org/")]
        [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
        public class Handler1 : IHttpHandler
        {
    
            public void ProcessRequest(HttpContext context)
            {
                context.Response.ContentType = "text/plain";
    
                string loadname = context.Request["loadname"];
    
                string curBrowser = context.Request.Browser.Type.ToLower();
    
                string path = "/resource/" + loadname;
                 
                //对ie和chrome需要设置url编码
                if (curBrowser.Contains("internetexplorer") || curBrowser.Contains("chrome"))
                {
                    loadname = HttpUtility.UrlEncode(loadname); 
                }
    
               
               
                //设置消息头
                context.Response.AddHeader("Content-Disposition", "attachmen;filename=" + loadname);
                //下载文件
                context.Response.WriteFile(path);
    
    
            }
    
            public bool IsReusable
            {
                get
                {
                    return false;
                }
            }
        }
    }
  • 相关阅读:
    如何搜索 git 提交记录
    使用Mongo进行分页
    mongodb 数据自动备份
    linux 添加环境变量
    centos7安装bbr
    centos7安装node
    [shell]输出内容到剪切板
    centos 7 已经开启 22 端口但无法连接
    一些有趣的 js 包
    机房选择
  • 原文地址:https://www.cnblogs.com/zoro-zero/p/4012939.html
Copyright © 2011-2022 走看看