Sh.Common.WebHelper 1.0.1

dotnet add package Sh.Common.WebHelper --version 1.0.1
NuGet\Install-Package Sh.Common.WebHelper -Version 1.0.1
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Sh.Common.WebHelper" Version="1.0.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Sh.Common.WebHelper --version 1.0.1
#r "nuget: Sh.Common.WebHelper, 1.0.1"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Sh.Common.WebHelper as a Cake Addin
#addin nuget:?package=Sh.Common.WebHelper&version=1.0.1

// Install Sh.Common.WebHelper as a Cake Tool
#tool nuget:?package=Sh.Common.WebHelper&version=1.0.1

.net Core 3.1 Web 程序

<br>

权限等 再子类中进行限制

自定义文件上传

可用 Controller 方式 :FileManagerController 继承 他便可以了

,如果需要 限制上传 再实现类中限制

/// <summary>
/// 上传文件大小限制
/// </summary>
public virtual long FileSizeLimit { get; set; } = 2 * 1024 * 1024;
/// <summary>
/// 支持的扩展名
/// </summary>
public virtual string[] PermittedExtensions { get; set; } = { ".txt" };
/// <summary>
/// 存储位置
/// </summary>
/// 
private string _targetFilePath = "Upload";
  • Streaming上传文件信息:UploadStreamingPhysical
  • 单个上传文件:UploadFile
  • 多文件上传: UploadFiles
  • 获取 上传目录中的文件信息 :GetPhysicalFilesName
    public class NodeModel
    {
        public string Name { get; set; }
        public NodeTypeEnum Type { get; set; }
        public string FileExt { get; set; }
        public string Path { get; set; }
        public long Size { get; set; }
        public DateTime Cdate { get; set; }
        public List<NodeModel> NextNodeModel { get; set; }
    
    }
    
    public enum NodeTypeEnum
    {
        文件夹,
        文件
    }
    
  • 删除目录或者文件夹:DeletePhysical
PageModel 方式 继承:FileManagerPageModelModel

页面限制与上面一样 不同 是 页面资源 的绑定

[BindProperty]
public FileUploadPhysical FileUpload { get; set; }

类结构

public class FileUploadPhysical
{
    [Required]
    [Display(Name = "文件")]
    public IFormFile FormFile { get; set; }
}

上传支持 OnPostUploadAsync()

KinderEditer 的文件上传 处理 KindEditorFileManagerController

因为之前 用了国内开源的 Edetor 只有他的图有上传功能。所以 就用了他

此类 继承后可以直接使用 可修改的限定 都事 Pretected 的字段 再子类中 修改

Cors 跨域问题 asp .net core 中 配置

  • 命名空间:Sh.Common.WebHelper.Middlewares;
  • 使用发方:Setup.cs 方法 Configure 添加 app.UseCorsMiddleware()
  • 注意 :添加在路由上面
等价得配置如下:
ConfigureServices:
services.AddCors(options => options.AddPolicy("CorsPolicy",
    builder =>
        {
            builder.AllowAnyMethod()
                .SetIsOriginAllowed(_ => true)
                .AllowAnyHeader()
                .AllowCredentials();
     }));
Configure:
  app.UseCors("CorsPolicy");
我们的特定允许配置如下
 builder.WithOrigins(new string[] { "http://你的网址" })
                .AllowAnyMethod()
                .AllowAnyHeader()
                .AllowCredentials();
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp3.1 is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.1 593 6/4/2020
1.0.0 471 5/10/2020