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;
                }
            }
        }
    }
  • 相关阅读:
    迭代器生成器和协程函数
    装饰器
    对haproxy.conf文件的增删改查
    函数基础
    深入理解python字符编码
    python字符串列表字典常用方法
    委托的使用
    数据库连接
    输入输出流
    泛型集合的使用
  • 原文地址:https://www.cnblogs.com/zoro-zero/p/4012939.html
Copyright © 2011-2022 走看看