获得一个.NET应用程序的电流/主动安全区?安全区、电流、应用程序、主动

2023-09-04 00:57:01 作者:Ruthless(无情)

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

我已经找到了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

Assembly.Evidence是一个属性证据对象。从这里就可以列举证据并寻找其表现为一个区域< System.Security.Policy.Zone>元素。

应用软件系统安全性设计 3

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.