升级文件下载的缓存支持,增强缓存设定,支持VisualStudio的WebDev
Stone authored at 2014-06-25 14:35:04
1.51 KiB
X
using System;
using System.IO;
using System.Web;
using NewLife.Web;

namespace NewLife.CommonEntity.Web
{
    /// <summary>文件下载处理器,可以直接使用,也可以继承</summary>
    public class DownloadFile : AttachmentHttpHandler
    {
        #region 业务
        ///// <summary>响应</summary>
        ///// <param name="context"></param>
        ///// <param name="attachment"></param>
        ///// <param name="stream"></param>
        ///// <param name="dispositionMode"></param>
        //protected override void OnResponse(HttpContext context, IAttachment attachment, Stream stream, string dispositionMode)
        //{
        //    var wd = new WebDownload();
        //    wd.Stream = stream;
        //    wd.FileName = attachment.FileName;
        //    //if (!String.IsNullOrEmpty(dispositionMode)) wd.Mode = (WebDownload.DispositionMode)Enum.Parse(typeof(WebDownload.DispositionMode), dispositionMode);
        //    wd.Mode = WebDownload.DispositionMode.Attachment;
        //    if (!String.IsNullOrEmpty(attachment.ContentType)) wd.ContentType = attachment.ContentType;
        //    wd.Speed = 100;
        //    wd.Render();
        //}

        /// <summary>参数准备完毕,输出前</summary>
        /// <param name="wd"></param>
        protected override void OnReader(WebDownload wd)
        {
            base.OnReader(wd);

            wd.Mode = WebDownload.DispositionMode.Attachment;
            wd.Speed = 100;
        }
        #endregion
    }
}