获得一个.NET应用程序的电流/主动安全区? [英] Get current/active security zone of a .NET application?

查看:156
本文介绍了获得一个.NET应用程序的电流/主动安全区?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个奇怪的行为的应用程序,而只是为了验证,我想看看它是目前正在运行的安全区。

我已经找到了System.Security.SecurityZone枚举,但似乎无法找到任何会返回的这些,我下运行。

有没有人有什么建议吗?

基本上,我想看看我的应用程序在我的电脑上运行,内联网,互联网,不可信,可信,等等。


编辑:下面是次要的测试程序,我写了找到这个code,这要归功于 @blowdart

 使用系统;
使用的System.Reflection;

命名空间zone_check
{
    类节目
    {
        静态无效的主要(字串[] args)
        {
            Console.WriteLine(NET版本:+ Environment.Version);
            的foreach(在Assembly.GetExecutingAssembly对象EV()。证据)
            {
                如果(EV是System.Security.Policy.Zone)
                {
                    System.Security.Policy.Zone区=(System.Security.Policy.Zone)EV;
                    Console.WriteLine(安全区:+ zone.SecurityZone);
                    打破;
                }
            }
        }
    }
}
 

解决方案

您需要看中科院的证据,目前的组装;

this.GetType()。Assembly.Evidence

<一个href="http://msdn.microsoft.com/en-us/library/system.reflection.assembly.evidence.aspx">Assembly.Evidence是一个属性证据对象。从这里就可以列举证据并寻找其表现为一个区域&LT; System.Security.Policy.Zone&GT;元素。

I have an application that behaves oddly, and just to verify, I'd like to see which security zone it is currently running under.

I've found the System.Security.SecurityZone enum, but can't seem to find anything that will return which of these I'm running under.

Does anyone have any tips?

Basically I want to find out if my application is running in MyComputer, Intranet, Internet, Untrusted, Trusted, etc.


Edit: Here's the minor test-app I wrote to find this code, thanks to @blowdart.

using System;
using System.Reflection;

namespace zone_check
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine(".NET version: " + Environment.Version);
            foreach (Object ev in Assembly.GetExecutingAssembly().Evidence)
            {
                if (ev is System.Security.Policy.Zone)
                {
                    System.Security.Policy.Zone zone = (System.Security.Policy.Zone)ev;
                    Console.WriteLine("Security zone: " + zone.SecurityZone);
                    break;
                }
            }
        }
    }
}

解决方案

You need to look at the CAS evidence for the current assembly;

this.GetType().Assembly.Evidence

Assembly.Evidence is a property Evidence object. From this you can enumerate the evidence and look for the zone which appears as a <System.Security.Policy.Zone> element.

这篇关于获得一个.NET应用程序的电流/主动安全区?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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