Get current/active security zone of a .NET application?

后端 未结 3 1426
伪装坚强ぢ
伪装坚强ぢ 2021-01-12 19:03

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.Sec

相关标签:
3条回答
  • 2021-01-12 19:49

    You can also use

    Evidence e = Thread.CurrentThread.GetType().Assembly.Evidence;
    

    instead of

    this.GetType().Assembly.Evidence
    
    0 讨论(0)
  • 2021-01-12 19:58

    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.

    0 讨论(0)
  • 2021-01-12 20:03

    In .NET 3.5 you can simplify the code with LINQ:

    Zone z = a.Evidence.OfType<Zone>().First();
    

    From .NET 4.0 you have a convenient GetHostEvidence method:

    Zone z = Assembly.GetExecutingAssembly().Evidence.GetHostEvidence<Zone>();
    

    Note that from .NET 4.0 evidence classes derive from the EvidenceBase base class.

    HTH, György

    0 讨论(0)
提交回复
热议问题