SecureFileValidator 1.0.9
.NET 8.0
This package targets .NET 8.0. The package is compatible with this framework or higher.
.NET Framework 4.7
This package targets .NET Framework 4.7. The package is compatible with this framework or higher.
There is a newer version of this package available.
See the version list below for details.
See the version list below for details.
dotnet add package SecureFileValidator --version 1.0.9
NuGet\Install-Package SecureFileValidator -Version 1.0.9
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="SecureFileValidator" Version="1.0.9" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="SecureFileValidator" Version="1.0.9" />
<PackageReference Include="SecureFileValidator" />
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add SecureFileValidator --version 1.0.9
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: SecureFileValidator, 1.0.9"
#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.
#:package SecureFileValidator@1.0.9
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=SecureFileValidator&version=1.0.9
#tool nuget:?package=SecureFileValidator&version=1.0.9
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
SecureFileValidator
📦 強型別檔案簽章驗證器,支援 .NET 8 / .NET Framework 4.7
支援 DataAnnotation、Action Filter 驗證方式,可套用於 ASP.NET Core / MVC 控制器與表單檢查。
✅ 支援格式(依 magic number 檢查)
.jpg
,.jpeg
,.png
,.gif
,.bmp
,.tif
.pdf
,.docx
,.xlsx
,.zip
,.rar
,.7z
.mp3
,.mp4
,.avi
,.webp
,.exe
🔐 驗證方式
1. DataAnnotation 驗證(ASP.NET Core)
public class UploadModel
{
[ValidateFileSignature(AllowedExtensions = new[] { ".docx", ".xlsx" })]
public IFormFile File { get; set; }
}
驗證失敗會寫入 ModelState 錯誤,可搭配
TryValidateModel()
或TryUpdateModelAsync()
使用。
2. Action Filter 驗證(ASP.NET Core)
[ValidateFileSignature(FileParameterName = "file")]
public IActionResult Upload(IFormFile file) { ... }
或驗證所有表單中檔案:
[ValidateFileSignature]
public IActionResult Upload() { ... }
3. MVC (.NET Framework)
[ValidateFileSignature(FileParameterName = "file", AllowedExtensions = new[] { ".docx" })]
public ActionResult Upload(HttpPostedFileBase file)
🧪 單元測試
請見 SecureFileValidator.Tests
中範例,包括:
.png
冒充.docx
驗證失敗- 合法
.docx
驗證成功 - 驗證失敗時
ModelState
錯誤訊息檢查
🛠 安裝套件
若手動引用專案,請加入:
<ItemGroup Condition="'$(TargetFramework)' == 'net8.0'">
<PackageReference Include="Microsoft.AspNetCore.App" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'net47'">
<Reference Include="System.Web" />
</ItemGroup>
📄 授權
MIT License
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net8.0 is compatible. 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. net9.0 is compatible. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
.NET Framework | net47 is compatible. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
.NETFramework 4.7
- Microsoft.AspNet.Mvc (>= 5.2.7)
- System.ComponentModel.Annotations (>= 4.7.0)
- System.IO.Compression (>= 4.3.0)
- System.IO.Compression.ZipFile (>= 4.3.0)
-
net8.0
- Microsoft.AspNetCore.Http.Abstractions (>= 2.3.0)
- Microsoft.AspNetCore.Mvc.Core (>= 2.3.0)
-
net9.0
- Microsoft.AspNetCore.Http.Abstractions (>= 2.3.0)
- Microsoft.AspNetCore.Mvc.Core (>= 2.3.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.