<%@ WebHandler Language="C#" Class="disk_Down" %>

using System;
using System.Web;
using WebDisk_BLL;
using WebDisk_Model;
using System.IO;
public class disk_Down : IHttpHandler {

    public void ProcessRequest(HttpContext context)
    {
       
        context.Response.ContentType = "text/plain";
        if (context.Request["id"] != null)
        {
            disk_ResourceFile_BLL dataOper = new disk_ResourceFile_BLL();
            disk_ResourceFile_Model model = dataOper.GetModel(new Guid(context.Request["id"]));

            if (model == null)
            {
                context.Response.Write("不存在资源");
                context.Response.End();
            }

            string dir = String.Format(
                    context.Server.MapPath(
                        String.Format("~/{0}", model.df_path)
                    )
                );


            if (!File.Exists(dir))
            {
                context.Response.Write("不存在资源！");
                context.Response.End();
            }
            if (model != null)
            {
                string fileName = model.df_name;
                
               
                context.Response.ContentType = "application/octet-stream";
                context.Response.AppendHeader("Content-Length ", model.df_size.ToString());
                context.Response.ContentEncoding = System.Text.Encoding.GetEncoding("utf-8");
                context.Response.AddHeader(
                    "Content-Disposition", String.Format("attachment;filename={0}{1}",   HttpUtility.UrlEncode(fileName),model.df_ext)
                    );
                context.Response.TransmitFile(dir);
            }

           
            
        }
    }
 
    public bool IsReusable {
        get {
            return false;
        }

        
        
    }




}