IdentityPolicyRuleType Class

Microsoft.VisualBasic.Security

Represents a rule that defines the identity of a caller in an application domain.

This class is part of the System.Net.Security namespace, enabling fine-grained control over network security policies and the identities that are trusted to perform specific operations.

Contents

Syntax

C#

public sealed class IdentityPolicyRuleType : System.Configuration.ConfigurationElement
                
Visual Basic

Public NotInheritable Class IdentityPolicyRuleType
    Inherits System.Configuration.ConfigurationElement
                

Remarks

The IdentityPolicyRuleType class is used to define security policies that govern the access rights of different code identities. It allows developers to specify which identities are permitted to perform certain actions, contributing to a robust security framework within .NET applications, especially those dealing with network communication and inter-application domain interactions.

When configuring security policies, you might define rules based on evidence such as code origin, publisher, or application domain. This class provides a structured way to represent and manage these rules.

Properties

Name Description
Action Gets or sets the action to be performed when the rule matches.
Identity Gets or sets the identity associated with this rule.
PolicyLevelType Gets or sets the type of policy level this rule belongs to.
RuleType Gets or sets the type of the rule (e.g., identity-based, URL-based).

Methods

Name Description
DeserializeElement(System.Xml.XmlReader, Boolean) Deserializes an XML element into a ConfigurationElement object. (Overrides ConfigurationElement.DeserializeElement)
SerializeToXmlElement(System.Xml.XmlElement, System.Configuration.RuntimeSectionName) Serializes the current ConfigurationElement object to an XML element. (Overrides ConfigurationElement.SerializeToXmlElement)

Examples

Here's a conceptual example of how IdentityPolicyRuleType might be used within a configuration file (e.g., app.config or web.config) to define a security rule:

XML Configuration

<configuration>
  <system.net>
    <security>
      <policyRules>
        <add name="AllowSpecificIdentity"
             policyLevelType="FullTrust"
             ruleType="IdentityBased"
             identity="CN=MyTrustedPublisher, O=MyCompany, C=US"
             action="Allow" />
      </policyRules>
    </security>
  </system.net>
</configuration>
                

In C#, you would typically load and manipulate these configuration settings programmatically:

C# Example (Conceptual)

using System;
using System.Configuration;
using System.Net.Security;
using System.Xml;

// Assume 'policyRulesSection' is an instance of a custom ConfigurationSection
// that contains a collection of IdentityPolicyRuleType elements.

// Example of programmatically adding a rule (simplified)
// In a real scenario, you'd interact with ConfigurationSection and ConfigurationElement classes
try
{
    // This is a conceptual representation. Actual configuration manipulation can be complex.
    // You would typically find the section and add to its 'Elements' collection.
    Console.WriteLine("Conceptual: Rule added to configuration.");
    // Example:
    // var config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
    // var section = (MySecuritySection)config.GetSection("mySecuritySection"); // Custom section
    // var newRule = new IdentityPolicyRuleType { ... };
    // section.Rules.Add(newRule);
    // config.Save();
}
catch (Exception ex)
{
    Console.WriteLine($"Error: {ex.Message}");
}
                

Inheritance Hierarchy

System.Object
System.Configuration.ConfigurationElement
Microsoft.VisualBasic.Security.IdentityPolicyRuleType

Requirements

Namespace: System.Net.Security

Assembly: System.dll

Framework Versions: .NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.6, 4.7, 4.8