項目說明 1. 目前支持WebForm文件下載,後續支持Mvc 2. 支持下載文件加密以及下載限速 3. 項目源碼: "MasterChief.DotNet.Framework.Download" 4. Nuget:Install Package MasterChief.DotNet.Framewo ...
項目說明
- 目前支持WebForm文件下載,後續支持Mvc
- 支持下載文件加密以及下載限速
- 項目源碼:MasterChief.DotNet.Framework.Download
- Nuget:Install-Package MasterChief.DotNet.Framework.Download
- 歡迎PR,歡迎Star;
如何使用
通過MasterChief.DotNet.Core.Config構建下載配置文件
<?xml version="1.0" encoding="utf-16"?> <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; }
運行效果