在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