在C#中,如何判斷我的程序集是否在asp.net中的中等信任下運行?是否有類似於Debugger.IsAttached爲此?如何以編程方式告訴我是否在Medium Trust下運行?
2
A
回答
1
0
從dmitryr的博客post:
public static AspNetHostingPermissionLevel GetTrustLevel()
{
foreach (AspNetHostingPermissionLevel trustLevel in new AspNetHostingPermissionLevel[]
{
AspNetHostingPermissionLevel.Unrestricted,
AspNetHostingPermissionLevel.High,
AspNetHostingPermissionLevel.Medium,
AspNetHostingPermissionLevel.Low,
AspNetHostingPermissionLevel.Minimal
})
{
try
{
new AspNetHostingPermission(trustLevel).Demand();
}
catch (System.Security.SecurityException)
{
continue;
}
return trustLevel;
}
return AspNetHostingPermissionLevel.None;
}
0
或者您可以使用此略短版
public AspNetHostingPermissionLevel GetCurrentTrustLevel()
{
foreach (AspNetHostingPermissionLevel trustLevel in Enum.GetValues(typeof(AspNetHostingPermissionLevel)))
{
try
{
new AspNetHostingPermission(trustLevel).Demand();
}
catch (System.Security.SecurityException)
{
continue;
}
return trustLevel;
}
return AspNetHostingPermissionLevel.None;
}
可能重複:HTTP: //stackoverflow.com/questions/1064274/get-current-asp-net-trust-le VEL-編程 – 2011-01-19 13:55:53