System.Net.Security.CAS.UrlIdentityPermission Class

Summary

Represents a permission for a URL identity. This class allows you to control access to resources based on their URL. It is part of the Code Access Security (CAS) model in older versions of .NET Framework, primarily used for managing security policies and code trust.

Syntax

public sealed class UrlIdentityPermission : System.Security.CodeAccessSecurityAttribute

Requirements

  • Namespace: System.Net.Security
  • Assembly: System.dll
  • .NET Framework versions: Available in .NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.6, 4.7, 4.8.

Syntax

The following example shows the syntax for declaring an instance of the UrlIdentityPermission class.

using System;
using System.Net.Security;
using System.Security;

[assembly: UrlIdentityPermissionAttribute("http://www.contoso.com/", SecurityAction.RequestMinimum) ]

public class MyClass { ... }

The following example shows the syntax for the constructor.

public UrlIdentityPermission( PermissionState state )
public UrlIdentityPermission( string url )

Public Methods

  • Copy() - Creates and returns an identical copy of the current permission object.
  • Equals(object obj) - Determines whether the specified object is equal to the current object.
  • FromXml(SecurityElement e) - Reconstructs a security object with a specified state from an XML encoding.
  • GetHashCode() - Serves as a hash function for the current type.
  • GetType() - Gets the Type of the current instance.
  • Intersect(IPermission target) - Creates and returns a new permission that represents the intersection of the current permission and the specified permission.
  • IsSubsetOf(IPermission target) - Determines whether the current permission is a subset of the specified permission.
  • IsUnrestricted() - Checks if the permission is unrestricted.
  • ToXml() - Returns an XML encoding of the security object.
  • Union(IPermission target) - Creates and returns a new permission that represents the union of the current permission and the specified permission.
  • ToString() - Returns a string that represents the current object.

Protected Methods

Public Fields

  • Url - Gets the URL associated with this permission.

Remarks

The UrlIdentityPermission class is used to grant or deny access to resources based on their network location (URL). In the context of Code Access Security (CAS), it allows administrators to define security policies that restrict the actions of code originating from specific URLs.

For example, you could create a policy that allows code downloaded from http://www.trusted-site.com/ to have more privileges than code from http://www.untrusted-site.com/.

The UrlIdentityPermissionAttribute class can be used to apply security attributes to code elements, such as assemblies or methods, to request or assert specific permissions at compile time.

Note: Code Access Security (CAS) is largely deprecated in favor of modern security models like role-based security and the principle of least privilege. While still present in older .NET Framework versions, its use is generally discouraged in new development.

See Also

Last modified: 11/24/2023 Contributors: MSDN Community