Represents a URL that can be used in Code Access Security (CAS) policy. This class is part of the Visual Basic security model and allows for granular control over code access permissions based on the origin of code.
public sealed class CAS.Url : System.Security.Policy.IMembershipCondition
The CAS.Url class is used to define a membership condition based on the URL from which code originates. This is a fundamental component of Code Access Security (CAS) in .NET Framework, allowing administrators to grant specific permissions to code loaded from particular locations (e.g., specific websites, network shares).
When you create a CAS.Url object, you specify a URL pattern. Code Access Security then evaluates whether the origin of a piece of code matches this URL pattern. If it matches, the associated membership condition is met, and the permissions granted by the policy are applied to that code.
This class is particularly useful in scenarios where you need to control access to resources or operations based on the trust level associated with the code's source.
Initializes a new instance of the CAS.Url class with the specified URL.
urlCreates and returns an identical copy of the current membership condition.
Determines whether the specified object is equal to the current object.
Serves as the default hash function.
Creates and returns a new membership condition that represents the intersection of the current condition and the specified condition.
conditionReturns null if the intersection is empty.
Returns a string representation of the membership condition.
Returns a string representation of the membership condition, optionally excluding module information.
noModuletrue to exclude module information; otherwise, false.Returns a string representation of the membership condition, optionally excluding module and real tag information.
noModuletrue to exclude module information; otherwise, false.noRealTagtrue to exclude real tag information; otherwise, false.Returns a string representation of the membership condition, optionally excluding module, real tag, and version information.
noModuletrue to exclude module information; otherwise, false.noRealTagtrue to exclude real tag information; otherwise, false.noVersiontrue to exclude version information; otherwise, false.Returns a string representation of the membership condition, optionally excluding module, real tag, version, and URL information.
noModuletrue to exclude module information; otherwise, false.noRealTagtrue to exclude real tag information; otherwise, false.noVersiontrue to exclude version information; otherwise, false.noUrltrue to exclude URL information; otherwise, false.Returns a string representation of the membership condition with the specified zone tag.
tag
Imports System.Security.Policy
Imports Microsoft.VisualBasic.Security
' Create a URL membership condition for a specific website
Dim websiteUrl As String = "http://www.example.com/*"
Dim urlCondition As New CAS.Url(websiteUrl)
' Check if code from a specific URL satisfies this condition
Dim codeOriginUrl As String = "http://www.example.com/app/main.exe"
Dim assembly As System.Reflection.Assembly = System.Reflection.Assembly.GetExecutingAssembly()
Dim urlMembership As New Url(codeOriginUrl) ' In real CAS, you'd get this from the assembly
If urlCondition.Equals(urlMembership) Then
Console.WriteLine($"Code from {codeOriginUrl} satisfies the condition.")
Else
Console.WriteLine($"Code from {codeOriginUrl} does NOT satisfy the condition.")
End If
' Create a condition that is the intersection of two URL conditions
Dim anotherUrl As String = "http://www.example.com/app/*"
Dim anotherCondition As New CAS.Url(anotherUrl)
Dim intersectionCondition As IMembershipCondition = urlCondition.Intersect(anotherCondition)
If intersectionCondition IsNot Nothing Then
Console.WriteLine($"Intersection of conditions: {intersectionCondition.ToString()}")
Else
Console.WriteLine("Intersection of conditions is empty.")
End If
Hide Code