CAS.UrlRecognitionPrefix Property
Retrieves a string that identifies the host and application name for a URL.
Syntax
public static string CAS.UrlRecognitionPrefix { get; }
Remarks
The UrlRecognitionPrefix property is used to create an identity that can be used to grant or deny permissions to code running from a specific URL. This property returns a string that represents the host name and application name of the current URL. For example, if the current URL is http://www.example.com/myapp/default.aspx, the UrlRecognitionPrefix might return http://www.example.com/myapp/.
This property is particularly useful in scenarios where you need to control access to resources based on the origin of the code requesting them. By using the string returned by UrlRecognitionPrefix, you can configure security policies to allow or disallow specific actions for code originating from trusted locations.
UrlRecognitionPrefix may vary depending on the runtime environment and the specific URL. It is recommended to treat the returned value as an opaque identifier for the purpose of permission granting.
CAS class.
Examples
The following C# code example demonstrates how to retrieve and use the UrlRecognitionPrefix property to construct a UrlIdentityPermission:
using System;
using System.Net;
using System.Security.Policy;
public class Example
{
public static void Main(string[] args)
{
try
{
// Get the URL recognition prefix for the current application.
string urlPrefix = System.Security.Policy.Url.UrlRecognitionPrefix;
Console.WriteLine($"URL Recognition Prefix: {urlPrefix}");
// Create a UrlIdentityPermission based on the prefix.
UrlIdentityPermission urlPermission = new UrlIdentityPermission(urlPrefix);
// In a real application, you would use this permission
// to check or grant access to resources.
Console.WriteLine($"Constructed UrlIdentityPermission: {urlPermission.ToString()}");
}
catch (NotSupportedException)
{
Console.WriteLine("URL recognition is not supported in this environment.");
}
catch (Exception ex)
{
Console.WriteLine($"An error occurred: {ex.Message}");
}
}
}
Requirements
| Assembly | File |
|---|---|
| mscorlib.dll | System.dll |