在C#中如何判断我的程序集是否在asp.net中的中等信任下运行?是否有类似于Debugger.IsAttached的内容?
答案 0 :(得分:1)
答案 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;
}
答案 2 :(得分: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;
}