当前位置:   article > 正文

[开源]快速构建文件下载,支持文件加密,自定义限速

web服务器 下载文件 加密

项目说明

  1. 目前支持WebForm文件下载,后续支持Mvc
  2. 支持下载文件加密以及下载限速
  3. 项目源码:MasterChief.DotNet.Framework.Download
  4. Nuget:Install-Package MasterChief.DotNet.Framework.Download
  5. 欢迎Star,欢迎Issues;
如何使用
  1. 通过MasterChief.DotNet.Core.Config构建下载配置文件

    1. <?xml version="1.0" encoding="utf-16"?>
    2. <DownloadConfig xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    3. FileNameEncryptorIv="0102030405060708090a0a0c0d010208"
    4. FileNameEncryptorKey="DotnetDownloadConfig"
    5. LimitDownloadSpeedKb="1024"
    6. DownLoadMainDirectory="D:\OneDrive\软件\工具\">
    7. </DownloadConfig>
  2. 在WebForm下新建一般处理程序,并实现DownloadHandler抽象类

    1. /// <summary>
    2. /// FileDownloadHandler 的摘要说明
    3. /// </summary>
    4. public class FileDownloadHandler : DownloadHandler, IHttpHandler
    5. {
    6. public void ProcessRequest(HttpContext context)
    7. {
    8. var fileName = context.Request["fileName"];
    9. StartDownloading(context, fileName);
    10. }
    11. public bool IsReusable => false;
    12. public override void OnDownloadFailed(HttpContext context, string fileName, string filePath, string ex)
    13. {
    14. context.Response.Write(ex);
    15. }
    16. public override void OnDownloadSucceed(HttpContext context, string fileName, string filePath)
    17. {
    18. var result = $"文件[{fileName}]下载成功,映射路径:{filePath}";
    19. context.Response.Write(result);
    20. }
    21. }
  3. 在WebForm下载文件加密显示

    1. protected void Page_Load(object sender, EventArgs e)
    2. {
    3. string url = DownloadFileContext.Instance.EncryptFileName("typora-setup-x64.exe");
    4. link.NavigateUrl = "~/FileDownloadHandler.ashx?fileName=" + url;
    5. }
  4. 运行效果

    y4mz07s-7TWePH9-vdbzMh6bLSr54wYY1BKBCxZP2pq0XeW03rD77GGKUiWyNMKMKZg0jgAseQK1rkj04elBPRLTBhgCbp2Dhtf_Iy2yhDmMNeM03SXPicThVeg76G9C1FKCZrzr5pxjth2TiDzVV40gMOAvU7hhDm9GgIQRIiIvmMWgEQYYrfLRGnW1xO5vyDKmfYjAkfwnC2Mdaz7ArDBcg?width=504&height=112&cropmode=none

转载于:https://www.cnblogs.com/MeetYan/p/10658762.html

声明:本文内容由网友自发贡献,转载请注明出处:【wpsshop博客】
推荐阅读
相关标签
  

闽ICP备14008679号