如何检查,如果你正在运行在中信任的环境中的.NET? [英] How do you check if you are running in Medium Trust environment in .NET?

查看:144
本文介绍了如何检查,如果你正在运行在中信任的环境中的.NET?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的共享托管在GoDaddy的运行的网站(不是我的选择,因为它始终是中等信任),我有一些先进的功能,我想打开,如果应用程序运行在高度信任。

I am running a website on shared hosting at GoDaddy (not my choice, because it is always Medium Trust), and I have some advanced features that I would like to turn on if the application is run in High Trust.

所以想知道,如果有一种方式,如果应用程序运行在中信任的环境,.NET,以检查是否在运行?

So would like to know, if there is an way to check if at runtime if the application is running in Medium Trust environment in .NET?

推荐答案

您可以尝试以下code:

You could try the following code:

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

I got this from the following link: http://www.netomatix.com/development/webcaspermissions.aspx

下面是MSDN中链接的安全管理器和注册表的权限类:

here's links for the Security Manager and Registry Permission classes in MSDN:

http://msdn.microsoft.com/en-us/library/system.security.securitymanager.isgranted.aspxhttp://msdn.microsoft.com/en-us/library/system.security.permissions.registrypermission.aspx

您将需要添加一个引用System.Security程序,并添加使用的System.Security程序和System.Security.Permissions报表的一对夫妇。

You will need to add a reference to System.Security and add a couple of using statements for System.Security and System.Security.Permissions.

编辑:

补充后,尼克的评论:

您可以直接测试的asp.net安全级别:

You could test directly for the asp.net security level:

if (SecurityManager.IsGranted( new AspNetHostingPermission(AspNetHostingPermissionLevel.Medium)))
{Response.Write("Medium Trust level");}

这篇关于如何检查,如果你正在运行在中信任的环境中的.NET?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆