[研究]GCB,IIS,ASP.NET設定建議,.NET信任層級(trust leve)實測(一)
2025-01-21
環境:Visual Studio 2022 + ASP.NET + WebForm + Web Application + C# + SQL Server 2019 + SQL Server Management Studio (SSMS) 20.2
********************************************************************************
發現ASP.NET WebForm 預設建立的方案,使用 .NET Framework 4.8
程式只有顯示 test 字串,沒別的。
Default.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs"
Inherits="WebApplication1.Default" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title></title>
</head>
<body>
<form id="form1" runat="server">
test
</form>
</body>
</html>
|
Default.aspx.cs
using System;
namespace WebApplication1
{
public partial class Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
}
}
|
********************************************************************************
Deploy 到網站後,先測試網站正常
錯誤訊息
'/' 應用程式中發生伺服器錯誤。 安全性例外狀況 描述: 應用程式嘗試執行安全原則不允許的作業。如果要授與這個應用程式所需的權限,請聯繫您的系統管理員,或在組態檔中變更這個應用程式的信任層級。 例外狀況詳細資訊: System.Security.SecurityException: 要求已經失敗。 原始程式錯誤: 在執行目前 Web 要求期間,產生未處理的例外狀況。如需有關例外狀況來源與位置的資訊,可以使用下列的例外狀況堆疊追蹤取得。 堆疊追蹤: [SecurityException: 要求已經失敗。] System.RuntimeTypeHandle.GetTypeByName(String name, Boolean throwOnError, Boolean ignoreCase, Boolean reflectionOnly, StackCrawlMarkHandle stackMark, IntPtr pPrivHostBinder, Boolean loadTypeFromPartialName, ObjectHandleOnStack type) +0 System.RuntimeTypeHandle.GetTypeByName(String name, Boolean throwOnError, Boolean ignoreCase, Boolean reflectionOnly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean loadTypeFromPartialName) +96 System.Type.GetType(String typeName) +62 System.CodeDom.Compiler.CompilerInfo.get_IsCodeDomProviderTypeValid() +15 System.Web.Compilation.CompilationUtil.GetRecompilationHash(CompilationSection ps) +2406 System.Web.Configuration.CompilationSection.get_RecompilationHash() +110 System.Web.Compilation.BuildManager.CheckTopLevelFilesUpToDateInternal(Int64 cachedHash) +551 System.Web.Compilation.BuildManager.CheckTopLevelFilesUpToDate(Int64 cachedHash) +59 System.Web.Compilation.BuildManager.ExecutePreAppStart() +155 System.Web.Hosting.HostingEnvironment.Initialize(ApplicationManager appManager, IApplicationHost appHost, IConfigMapPathFactory configMapPathFactory, HostingEnvironmentParameters hostingParameters, PolicyLevel policyLevel, Exception appDomainCreationException) +746 版本資訊: Microsoft .NET Framework 版本:4.0.30319; ASP.NET 版本:4.8.4797.0 |
********************************************************************************
ASP.NET WebForm,System.Security.Permissions.ReflectionPermission 是甚麼 ?
System.Security.Permissions.ReflectionPermission 不是第三方套件,而是:
- 👉 .NET Framework 內建的類別
- 👉 隸屬於 程式碼存取安全性(Code Access Security, CAS) 架構
📦 所屬 Assembly(組件):mscorlib.dll
也就是說:
- 不需要安裝 NuGet
- 不需要額外引用 DLL
- 只要是 .NET Framework(非 .NET Core / .NET 5+) 都一定存在
相關
.NET Framework 生命週期
https://learn.microsoft.com/zh-tw/lifecycle/products/microsoft-net-framework

沒有留言:
張貼留言