2025年11月13日 星期四

[研究]「ASP.NET 部分信任 (Partial Trust)」的 3rd Party 套件/元件支援狀況

[研究]「ASP.NET <trust level> 部分信任 (Partial Trust)」的 3rd Party 套件/元件支援狀況

2025-11-13

ChatGPT

ASP.NET trust level(Full, High, Medium, Low, Minimal)主要限制了應用程式可以存取的系統資源,例如檔案系統、反射、COM、非託管程式碼等。許多現代套件在 Medium 或以下環境會無法正常運作,尤其是需要以下功能的套件:

  • 反射(Reflection.Emit 或動態產生程式碼)
  • 非託管程式碼或 P/Invoke
  • IO 權限(存取檔案、暫存、Temp 等)
  • 網路請求(System.Net.HttpClient 或 Sockets)

這是一個非常關鍵的問題,因為「ASP.NET <trust level> 部分信任 (Partial Trust)」的支援狀況,確實隨著 .NET Framework 版本演進逐步退場。

以下是套件在不同 trust level 下可能的行為整理表(依經驗與官方文件判斷,實際還需測試):

Trust Level 可能異常套件 原因 / 說明
High 幾乎所有套件可用 High 幾乎接近 Full trust,允許大部分程式碼執行,僅限制部分高權限操作(如 COM、非託管呼叫)。
Medium Aspose.Cells, FreeSpire.PDF, NReco.PdfGenerator, WkHtmlToPdf, System.Reflection.Emit 相關套件(FastMember, LinqKit) Medium 禁止部分 Reflection.Emit、P/Invoke、檔案系統高權限操作,PDF、Excel、PDF 生成與動態型別映射可能失敗。
Low 幾乎所有需要 IO/Reflection/非託管的套件:Aspose.Cells, FreeSpire.PDF, NReco.PdfGenerator, WkHtmlToPdf, FastMember, LinqKit, AngleSharp (部分 CSS/JS parsing 可能失敗) Low 禁止非託管程式碼與 Reflection.Emit,大量套件在動態型別生成、檔案寫入、網路請求會失效。
Minimal 幾乎全部套件(PDF, Excel, JSON, WebApi, Owin, Autofac, SendGrid, MailKit) Minimal 只允許最基本 CLR 功能,網路、檔案、反射、非託管全部被禁止,現代套件幾乎全都異常。

重點說明:

  • PDF/Excel 套件(Aspose.Cells、FreeSpire.PDF、ClosedXML、NReco.PdfGenerator):通常需要檔案寫入或 Reflection.Emit,Medium 以下就可能失敗。
  • 動態型別/Reflection(FastMember、LinqKit、Enums.NET):Medium 以下禁止 Reflection.Emit,會拋出 SecurityException。
  • 網路/IO 操作(SendGrid、MailKit、RestSharp、HttpClient):Low 或 Minimal 可能被阻擋。
  • 非託管/COM(WkHtmlToPdf、Oracle.ManagedDataAccess):Medium 以下通常無法運作。
  • 前端套件(jQuery, Bootstrap, Moment.js 等)對 ASP.NET trust level 無影響,因為這些都是純 client-side。

套件名稱 版本 High Medium Low Minimal
AngleSharp 0.17.1 ⚠️
AngleSharp.Css 0.17.0 ⚠️
Antlr 3.5.0.2 ⚠️
Aspose.Cells 25.10.0 ⚠️
Autofac 8.4.0
Autofac.WebApi2 6.1.1 ⚠️
Bootstrap.Datepicker 1.8.0.1
BouncyCastle.Cryptography 2.6.2 ⚠️
ByteSize 2.1.2 ⚠️
Chart.js 3.7.1
ClosedXML 0.105.0 ⚠️
ClosedXML.Parser 2.0.0 ⚠️
Common.Logging 3.4.1 ⚠️
Common.Logging.Core 3.4.1 ⚠️
DocumentFormat.OpenXml 3.3.0 ⚠️
DocumentFormat.OpenXml.Framework 3.3.0 ⚠️
EFUtilities 1.0.2 ⚠️
EntityFramework 6.5.1 ⚠️
Enums.NET 5.0.0 ⚠️
ExcelDataReader 3.8.0 ⚠️
ExcelDataReader.DataSet 3.8.0 ⚠️
ExcelNumberFormat 1.1.0 ⚠️
ExtendedNumerics.BigDecimal 3001.1.0.233 ⚠️
FastMember 1.5.0 ⚠️
FastMember.Signed 1.5.0 ⚠️
Font.Awesome 5.15.4
FontAwesome 4.7.0
FreeDataExports 1.1.12 ⚠️
FreeSpire.PDF 8.6.0 ⚠️
HtmlSanitizer 9.0.876 ⚠️
HtmlSanitizer 9.0.886 ⚠️
Irony 1.5.3 ⚠️
Irony.NetCore 1.1.11 ⚠️
JetBrains.Annotations 2025.2.2 ⚠️
LinqKit 1.3.8 ⚠️
LinqKit.Core 1.2.8 ⚠️
LogicExtensions 0.0.3 ⚠️
MailKit 4.14.1 ⚠️
MathNet.Numerics.Signed 5.0.0 ⚠️
Microsoft.AspNet.FriendlyUrls 1.0.2 ⚠️
Microsoft.AspNet.FriendlyUrls.Core 1.0.2 ⚠️
Microsoft.AspNet.FriendlyUrls.Core.zh-Hant 1.0.2 ⚠️
Microsoft.AspNet.Identity.Core 2.2.4 ⚠️
Microsoft.AspNet.Identity.Core.zh-Hant 2.2.4 ⚠️
Microsoft.AspNet.Identity.EntityFramework 2.2.4 ⚠️
Microsoft.AspNet.Identity.EntityFramework.zh-Hant 2.2.4 ⚠️
Microsoft.AspNet.Identity.Owin 2.2.4 ⚠️
Microsoft.AspNet.Identity.Owin.zh-Hant 2.2.4 ⚠️
Microsoft.AspNet.Providers.Core 2.0.0 ⚠️
Microsoft.AspNet.Providers.Core.zh-Hant 2.0.0 ⚠️
Microsoft.AspNet.ScriptManager.MSAjax 5.0.0 ⚠️
Microsoft.AspNet.ScriptManager.WebForms 5.0.0 ⚠️
Microsoft.AspNet.Web.Optimization 1.1.3 ⚠️
Microsoft.AspNet.Web.Optimization.WebForms 1.1.3 ⚠️
Microsoft.AspNet.Web.Optimization.zh-Hans 1.1.3 ⚠️
Microsoft.AspNet.Web.Optimization.zh-Hant 1.1.3 ⚠️
Microsoft.AspNet.WebApi 5.3.0 ⚠️
Microsoft.AspNet.WebApi.Client 6.0.0 ⚠️
Microsoft.AspNet.WebApi.Client.zh-Hant 6.0.0 ⚠️
Microsoft.AspNet.WebApi.Core 5.3.0 ⚠️
Microsoft.AspNet.WebApi.Core.zh-Hant 5.3.0 ⚠️
Microsoft.AspNet.WebApi.WebHost 5.3.0 ⚠️
Microsoft.AspNet.WebApi.WebHost.zh-Hant 5.3.0 ⚠️
Microsoft.Bcl.AsyncInterfaces 9.0.10 ⚠️
Microsoft.Bcl.Build 1.0.21 ⚠️
Microsoft.Bcl.Cryptography 9.0.10 ⚠️
Microsoft.Bcl.HashCode 6.0.0 ⚠️
Microsoft.CSharp 4.7.0 ⚠️
Microsoft.Extensions.DependencyInjection 9.0.10 ⚠️
Microsoft.Extensions.DependencyInjection.Abstractions 9.0.10 ⚠️
Microsoft.IO.RecyclableMemoryStream 3.0.1 ⚠️
Microsoft.NETCore.Platforms 7.0.4 ⚠️
Microsoft.Owin 4.2.3 ⚠️
Microsoft.Owin.Host.SystemWeb 4.2.3 ⚠️
Microsoft.Owin.Security 4.2.3 ⚠️
Microsoft.Owin.Security.Cookies 4.2.3 ⚠️
Microsoft.Owin.Security.OAuth 4.2.3 ⚠️
Microsoft.Web.Infrastructure 2.0.0 ⚠️
Microsoft.Win32.Primitives 4.3.0 ⚠️
MimeKit 4.14.0 ⚠️
Modernizr 2.8.3 ⚠️
Modernizr.New 3.4.0 ⚠️
Moment.js 2.30.1 ⚠️
NETStandard.Library 2.0.3 ⚠️
NLog 6.0.5 ⚠️
NLog.Schema 6.0.5 ⚠️
NPOI 2.7.5 ⚠️
NReco.PdfGenerator 1.2.1 ⚠️
NSax 1.0.2 ⚠️
Newtonsoft.Json 13.0.4 ⚠️
Newtonsoft.Json.Bson 1.0.3 ⚠️
Npoi.Mapper 6.2.2 ⚠️
Oracle.ManagedDataAccess 23.26.0 ⚠️
Owin 1.0 ⚠️
Portable.BouncyCastle 1.9.0 ⚠️
ProDotNetZip 1.20.0 ⚠️
RBush 4.0.0 ⚠️
RBush.Signed 4.0.0 ⚠️
Respond 1.4.2 ⚠️
RestSharp 106.15.0 ⚠️
RestSharp 112.1.0 ⚠️
Select2.js 4.0.13 ⚠️
SendGrid 9.29.3 ⚠️
SendGrid.CSharp.HTTP.Client 3.4.12 ⚠️
SendGrid.SmtpApi 1.4.6 ⚠️
SharpZipLib 1.4.2 ⚠️
SixLabors.Fonts 1.0.1 ⚠️
SixLabors.ImageSharp 3.1.11 ⚠️
Swashbuckle 5.6.0 ⚠️
Swashbuckle.Core 5.6.0 ⚠️
System.AppContext 4.3.0 ⚠️
System.Buffers 4.6.1 ⚠️
System.Collections 4.3.0 ⚠️
System.Collections.Concurrent 4.3.0 ⚠️
System.Collections.Immutable 9.0.10 ⚠️
System.Configuration.ConfigurationManager 9.0.10 ⚠️
System.Console 4.3.1 ⚠️
System.Diagnostics.Debug 4.3.0 ⚠️
System.Diagnostics.DiagnosticSource 9.0.10 ⚠️
System.Diagnostics.Tools 4.3.0 ⚠️
System.Diagnostics.Tracing 4.3.0 ⚠️
System.Formats.Asn1 9.0.10 ⚠️
System.Globalization 4.3.0 ⚠️
System.Globalization.Calendars 4.3.0 ⚠️
System.IO 4.3.0 ⚠️
System.IO.Compression 4.3.0 ⚠️
System.IO.Compression.ZipFile 4.3.0 ⚠️
System.IO.FileSystem 4.3.0 ⚠️
System.IO.FileSystem.Primitives 4.3.0 ⚠️
System.IO.Packaging 9.0.10 ⚠️
System.IO.Pipelines 9.0.10 ⚠️
System.IO.UnmanagedMemoryStream 4.3.0 ⚠️
System.Linq 4.3.0 ⚠️
System.Linq.Dynamic.Core 1.6.9 ⚠️
System.Linq.Expressions 4.3.0 ⚠️
System.Linq.Queryable 4.3.0 ⚠️
System.Memory 4.6.3 ⚠️
System.Net.Http 4.3.4 ⚠️
System.Net.Primitives 4.3.1 ⚠️
System.Net.Sockets 4.3.0 ⚠️
System.Numerics.Vectors 4.6.1 ⚠️
System.ObjectModel 4.3.0 ⚠️
System.Reflection 4.3.0 ⚠️
System.Reflection.Emit.ILGeneration 4.7.0 ⚠️
System.Reflection.Emit.Lightweight 4.7.0 ⚠️
System.Reflection.Extensions 4.3.0 ⚠️
System.Reflection.Primitives 4.3.0 ⚠️
System.Resources.ResourceManager 4.3.0 ⚠️
System.Runtime 4.3.1 ⚠️
System.Runtime.CompilerServices.Unsafe 6.1.2 ⚠️
System.Runtime.CompilerServices.Unsafe 7.0.0-preview.2.22152.2 ⚠️
System.Runtime.Extensions 4.3.1 ⚠️
System.Runtime.Handles 4.3.0 ⚠️
System.Runtime.InteropServices 4.3.0 ⚠️
System.Runtime.InteropServices.RuntimeInformation 4.3.0 ⚠️
System.Runtime.Numerics 4.3.0 ⚠️
System.Security.AccessControl 6.0.1 ⚠️
System.Security.Cryptography.Algorithms 4.3.1 ⚠️
System.Security.Cryptography.Encoding 4.3.0 ⚠️
System.Security.Cryptography.Pkcs 9.0.10 ⚠️
System.Security.Cryptography.Primitives 4.3.0 ⚠️
System.Security.Cryptography.X509Certificates 4.3.2 ⚠️
System.Security.Cryptography.Xml 9.0.10 ⚠️
System.Security.Permissions 9.0.10 ⚠️
System.Security.Principal.Windows 5.0.0 ⚠️
System.Text.Encoding 4.3.0 ⚠️
System.Text.Encoding.CodePages 9.0.10 ⚠️
System.Text.Encoding.Extensions 4.3.0 ⚠️
System.Text.Encodings.Web 9.0.10 ⚠️
System.Text.Json 9.0.10 ⚠️
System.Text.RegularExpressions 4.3.1 ⚠️
System.Threading 4.3.0 ⚠️
System.Threading.Tasks 4.3.0 ⚠️
System.Threading.Tasks.Extensions 4.6.3 ⚠️
System.Threading.Tasks.Parallel 4.3.0 ⚠️
System.Threading.Timer 4.3.0 ⚠️
System.ValueTuple 4.5.0 ⚠️
System.ValueTuple 4.6.1 ⚠️
System.Xml.Linq 3.5.21022.801 ⚠️
System.Xml.ReaderWriter 4.3.1 ⚠️
System.Xml.XDocument 4.3.0 ⚠️
WebActivatorEx 2.2.0 ⚠️
WebGrease 1.6.0 ⚠️
WkHtmlToPdf 1.0.2 ⚠️
X.PagedList 10.5.9 ⚠️
XLParser 1.7.5 ⚠️
ZString 2.6.0 ⚠️
bootstrap 3.4.1 ⚠️
bootstrap 5.3.8 ⚠️
elmah 1.2.2 ⚠️
elmah.corelibrary 1.2.2 ⚠️
html5-shiv 3.7.3 ⚠️
icheck-bootstrap 3.0.1 ⚠️
jQuery 3.7.1 ⚠️
jQuery-datetimepicker 2.4.5 ⚠️
jQuery.UI.Combined 1.14.1 ⚠️
jQuery.Validation 1.21.0 ⚠️
js-cookie 2.2.1 ⚠️
popper.js 1.16.1 ⚠️
starkbank-ecdsa 1.3.3 ⚠️
vue 2.6.11 ⚠️

(完)

相關

[研究]「ASP.NET 部分信任 (Partial Trust)」的 3rd Party 套件/元件支援狀況https://shaurong.blogspot.com/2025/11/aspnet-partial-trust-3rd-party.html

[研究]GCB,IIS,\system.web\trust\level 變更影響?
https://shaurong.blogspot.com/2025/11/gcbiissystemwebtrustlevel.html

[研究]「ASP.NET 部分信任 (Partial Trust)」的支援狀況
https://shaurong.blogspot.com/2025/11/aspnet-partial-trust.html



沒有留言:

張貼留言