CreateFromUrl() public static method

public static CreateFromUrl ( string url ) : System.Security.Policy.Zone
url string
return System.Security.Policy.Zone
        private static string GetZoneNameFromDeploymentUrl(string deploymentUrl)
        {
            Zone zone = Zone.CreateFromUrl(deploymentUrl);

            if ((zone != null) && (zone.SecurityZone != SecurityZone.NoZone))
            {
                switch (zone.SecurityZone)
                {
                case SecurityZone.MyComputer:
                    return("MyComputer");

                case SecurityZone.Intranet:
                    return("LocalIntranet");

                case SecurityZone.Trusted:
                    return("TrustedSites");

                case SecurityZone.Internet:
                    return("Internet");

                case SecurityZone.Untrusted:
                    return("UntrustedSites");
                }
            }
            return("UntrustedSites");
        }
Ejemplo n.º 2
0
        static internal Evidence GetDefaultHostEvidence(Assembly a)
        {
            Evidence e     = new Evidence();
            string   aname = a.EscapedCodeBase;

            // by default all assembly have the Zone, Url and Hash evidences
            e.AddHost(Zone.CreateFromUrl(aname));
            e.AddHost(new Url(aname));
            e.AddHost(new Hash(a));

            // non local files (e.g. http://) also get a Site evidence
            if (String.Compare("FILE://", 0, aname, 0, 7, true, CultureInfo.InvariantCulture) != 0)
            {
                e.AddHost(Site.CreateFromUrl(aname));
            }

            // strongnamed assemblies gets a StrongName evidence
            AssemblyName an = a.GetName();

            byte[] pk = an.GetPublicKey();
            if ((pk != null) && (pk.Length > 0))
            {
                StrongNamePublicKeyBlob blob = new StrongNamePublicKeyBlob(pk);
                e.AddHost(new StrongName(blob, an.Name, an.Version));
            }

            // Authenticode(r) signed assemblies get a Publisher evidence
            if (IsAuthenticodePresent(a))
            {
                try {
                    X509Certificate x509 = X509Certificate.CreateFromSignedFile(a.Location);
                    e.AddHost(new Publisher(x509));
                }
                catch (CryptographicException) {
                }
            }

            // assemblies loaded from the GAC also get a Gac evidence (new in Fx 2.0)
            if (a.GlobalAssemblyCache)
            {
                e.AddHost(new GacInstalled());
            }

            // the current HostSecurityManager may add/remove some evidence
            AppDomainManager dommgr = AppDomain.CurrentDomain.DomainManager;

            if (dommgr != null)
            {
                if ((dommgr.HostSecurityManager.Flags & HostSecurityManagerOptions.HostAssemblyEvidence) ==
                    HostSecurityManagerOptions.HostAssemblyEvidence)
                {
                    e = dommgr.HostSecurityManager.ProvideAssemblyEvidence(a, e);
                }
            }

            return(e);
        }