题
我在共享GoDaddy的托管运行的网站(不是我的选择,因为它始终是中等信任),我有一些先进的功能,我想打开,如果应用程序在高度信任运行。
所以想知道,如果在运行时,如果应用程序在中信任的环境中运行的.NET检查的方法是什么?
解决方案
您可以尝试下面的代码:
if (!SecurityManager.IsGranted(new RegistryPermission(PermissionState.Unrestricted)))
{
//do something.... not at full trust
}
if (!SecurityManager.IsGranted(new DnsPermission(PermissionState.Unrestricted)))
{
//do something.... not at full trust
}
我得到这个从下面的链接: http://www.netomatix.com/development/webcaspermissions.aspx
这里的安全管理器和注册表的权限类的链接在MSDN:
http://msdn.microsoft.com /en-us/library/system.security.securitymanager.isgranted.aspx http://msdn.microsoft.com/en-我们/库/ system.security.permissions.registrypermission.aspx
您将需要添加到System.Security的引用,并添加使用System.Security和System.Security.Permissions语句的一对夫妇。
编辑:
添加尼克的注释后:
您可以用于asp.net安全级别直接测试:
if (SecurityManager.IsGranted( new AspNetHostingPermission(AspNetHostingPermissionLevel.Medium)))
{Response.Write("Medium Trust level");}
不隶属于 StackOverflow