项目说明
- 目前支持WebForm文件下载,后续支持Mvc
- 支持下载文件加密以及下载限速
- 项目源码:MasterChief.DotNet.Framework.Download
- Nuget:Install-Package MasterChief.DotNet.Framework.Download
- 欢迎Star,欢迎Issues;
如何使用#
-
通过MasterChief.DotNet.Core.Config构建下载配置文件
"1.0" encoding="utf-16" xml version=<DownloadConfig xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" FileNameEncryptorIv="0102030405060708090a0a0c0d010208" FileNameEncryptorKey="DotnetDownloadConfig" LimitDownloadSpeedKb="1024" DownLoadMainDirectory="D:\OneDrive\软件\工具\"> </DownloadConfig>
-
在WebForm下新建一般处理程序,并实现DownloadHandler抽象类
/// <summary> /// FileDownloadHandler 的摘要说明 /// </summary> public class FileDownloadHandler : DownloadHandler, IHttpHandler { public void ProcessRequest(HttpContext context) { var fileName = context.Request["fileName"]; StartDownloading(context, fileName); } public bool IsReusable => false; public override void OnDownloadFailed(HttpContext context, string fileName, string filePath, string ex) { context.Response.Write(ex); } public override void OnDownloadSucceed(HttpContext context, string fileName, string filePath) { var result = $"文件[{fileName}]下载成功,映射路径:{filePath}"; context.Response.Write(result); } }
-
在WebForm下载文件加密显示
protected void Page_Load(object sender, EventArgs e) { string url = DownloadFileContext.Instance.EncryptFileName("typora-setup-x64.exe"); link.NavigateUrl = "~/FileDownloadHandler.ashx?fileName=" + url; }
-
运行效果