SiteIdentityPermission Class
Assembly: mscorlib (in mscorlib.dll)
'Declaration <SerializableAttribute> _ <ComVisibleAttribute(True)> _ Public NotInheritable Class SiteIdentityPermission Inherits CodeAccessPermission 'Usage Dim instance As SiteIdentityPermission
/** @attribute SerializableAttribute() */ /** @attribute ComVisibleAttribute(true) */ public final class SiteIdentityPermission extends CodeAccessPermission
SerializableAttribute ComVisibleAttribute(true) public final class SiteIdentityPermission extends CodeAccessPermission
Using this class, it is possible to ensure that callers are from a specific Web site. Site identity is only defined for code from URLs with the protocols of HTTP, HTTPS, and FTP. A site is the string between the "//" after the protocol of a URL and the following "/", if present, for example, www.fourthcoffee.com in the URL http://www.fourthcoffee.com/process/grind.htm. This excludes port numbers. If a given URL is http://www.fourthcoffee.com:8000/, the site is www.fourthcoffee.com, not www.fourthcoffee.com:8000.
Sites can be matched exactly, or by a wildcard ("*") prefix at the dot delimiter. For example, the site name string *.fourthcoffee.com matches fourthcoffee.com as well as www.fourthcoffee.com. Without a wildcard, the site name must be a precise match. The site name string * will match any site, but will not match code that has no site evidence.
Caution |
|---|
| SiteIdentityPermission grants permission for all paths to the site, including both the URL and the IP address. To Deny access to a site, you must Deny all possible paths to the site. For example, if www.fourthcoffee.com is located at IP address 192.168.238.241, to Deny access to www.fourthcoffee.com, you must Deny www.fourthcoffee.com, 192.168.238.241 and any other path that you can use to access the site. A better technique to deal with multiple paths is to use a combination of PermitOnly and Deny. For more information on this subject and the use of PermitOnly with Deny, see Canonicalization Problems Using Deny in the Using the Deny Method topic. |
Note |
|---|
| In the .NET Framework versions 1.0 and 1.1, identity permissions cannot have an Unrestricted permission state value. In the .NET Framework version 2.0, identity permissions can have any permission state value. This means that in version 2.0, identity permissions have the same behavior as permissions that implement the IUnrestrictedPermission interface. For information on executing version 2.0 applications with version 1.1 CAS policy, see <legacyV1CASPolicy> Element. |
Imports System Imports System.Security Imports System.Security.Permissions Imports Microsoft.VisualBasic <Assembly: CLSCompliant(True)> Public Class SiteIdentityPermissionDemo ' IsSubsetOf determines whether the current permission is a subset of the specified permission. Private Function IsSubsetOfDemo() As Boolean Dim returnCodeCode As Boolean = True Dim site1 As [String] = "" Dim site2 As [String] = "" Dim siteIdPerm1, siteIdPerm2 As SiteIdentityPermission Dim siteGen1 As New SiteGenerator() Dim siteGen2 As New SiteGenerator() siteGen1.ResetIndex() While siteGen1.CreateSite(site1) siteIdPerm1 = siteGen1.CreatePerm(site1) If siteIdPerm1 Is Nothing Then GoTo ContinueWhile1 End If siteGen2.ResetIndex() Console.WriteLine("**************************************************************************") While siteGen2.CreateSite(site2) Try siteIdPerm2 = siteGen2.CreatePerm(site2) If siteIdPerm2 Is Nothing Then GoTo ContinueWhile2 End If If siteIdPerm1.IsSubsetOf(siteIdPerm2) Then Console.WriteLine((site1 & " is a subset of " & site2)) Else Console.WriteLine((site1 & " is not a subset of " & site2)) End If Catch e As Exception Console.WriteLine(("An exception was thrown : " & e.ToString())) Return False End Try ContinueWhile2: End While ContinueWhile1: End While Return returnCodeCode End Function 'IsSubsetOfDemo ' Union creates a new permission that is the union of the current permission ' and the specified permission. Private Function UnionDemo() As Boolean Dim returnCodeCode As Boolean = True Dim site1 As [String] = "" Dim site2 As [String] = "" Dim siteIdPerm1, siteIdPerm2, p3 As SiteIdentityPermission Dim siteGen1 As New SiteGenerator() Dim siteGen2 As New SiteGenerator() siteGen1.ResetIndex() While siteGen1.CreateSite(site1) siteIdPerm1 = siteGen1.CreatePerm(site1) If siteIdPerm1 Is Nothing Then GoTo ContinueWhile1 End If siteGen2.ResetIndex() Console.WriteLine("**************************************************************************") While siteGen2.CreateSite(site2) siteIdPerm2 = siteGen2.CreatePerm(site2) If siteIdPerm2 Is Nothing Then GoTo ContinueWhile2 End If Dim firstSite As [String] = IIf(site1 Is Nothing, "null", site1) Dim secondSite As [String] = IIf(site2 Is Nothing, "null", site2) Try p3 = CType(siteIdPerm1.Union(siteIdPerm2), SiteIdentityPermission) Dim thirdSite As [String] = IIf(p3.Site Is Nothing, "null", p3.Site.ToString()) If Not (p3 Is Nothing) Then Console.WriteLine(("The union of " & firstSite & " and " & ControlChars.Lf & ControlChars.Tab & secondSite & " = " & ControlChars.Lf & ControlChars.Tab & thirdSite & ControlChars.Lf)) Else Console.WriteLine(("The union of " & firstSite & " and " & ControlChars.Lf & ControlChars.Tab & secondSite & " = null." & ControlChars.Lf)) End If Catch e As Exception ' Expected exception, result of the union is null. Console.WriteLine((e.Message & firstSite & " and " & ControlChars.Lf & ControlChars.Tab & secondSite & ControlChars.Lf)) End Try ContinueWhile2: End While ContinueWhile1: End While Return returnCodeCode End Function 'UnionDemo ' Intersect creates and returns a new permission that is the intersection of the ' current permission and the permission specified. Private Function IntersectDemo() As Boolean Dim returnCodeCode As Boolean = True Dim site1 As [String] = "" Dim site2 As [String] = "" Dim siteIdPerm1, siteIdPerm2, p3 As SiteIdentityPermission Dim siteGen1 As New SiteGenerator() Dim siteGen2 As New SiteGenerator() siteGen1.ResetIndex() While siteGen1.CreateSite(site1) siteIdPerm1 = siteGen1.CreatePerm(site1) If siteIdPerm1 Is Nothing Then GoTo ContinueWhile1 End If siteGen2.ResetIndex() Console.WriteLine("**************************************************************************") While siteGen2.CreateSite(site2) siteIdPerm2 = siteGen2.CreatePerm(site2) If siteIdPerm2 Is Nothing Then GoTo ContinueWhile2 End If Dim firstSite As [String] = IIf(site1 Is Nothing, "null", site1) Dim secondSite As [String] = IIf(site2 Is Nothing, "null", site2) Try p3 = CType(siteIdPerm1.Intersect(siteIdPerm2), SiteIdentityPermission) Dim thirdSite As [String] = IIf(p3.Site Is Nothing, "null", p3.Site.ToString()) If Not (p3 Is Nothing) Then Console.WriteLine(("The intersection of " & firstSite & " and " & ControlChars.Lf & ControlChars.Tab & secondSite & " = " & thirdSite & ControlChars.Lf)) Else Console.WriteLine(("The intersection of " & firstSite & " and " & ControlChars.Lf & ControlChars.Tab & secondSite & " = null." & ControlChars.Lf)) End If Catch Console.WriteLine(("The intersection of " & firstSite & " and " & ControlChars.Lf & ControlChars.Tab & secondSite & " = null." & ControlChars.Lf)) End Try ContinueWhile2: End While ContinueWhile1: End While Return returnCodeCode End Function 'IntersectDemo 'Copy creates and returns an identical copy of the current permission. Private Function CopyDemo() As Boolean Dim returnCodeCode As Boolean = True Dim site1 As [String] = "" Dim siteIdPerm1, siteIdPerm2 As SiteIdentityPermission Dim siteGen1 As New SiteGenerator() Dim siteGen2 As New SiteGenerator() siteGen1.ResetIndex() While siteGen1.CreateSite(site1) siteIdPerm1 = siteGen1.CreatePerm(site1) If siteIdPerm1 Is Nothing Then GoTo ContinueWhile1 End If siteGen2.ResetIndex() Console.WriteLine("**************************************************************************") Try siteIdPerm2 = CType(siteIdPerm1.Copy(), SiteIdentityPermission) If Not (siteIdPerm2 Is Nothing) Then Console.WriteLine(("The copy of " & siteIdPerm2.ToString() & " succeeded." & ControlChars.Lf)) End If Catch e As Exception Console.WriteLine(("The copy failed : " & siteIdPerm1.ToString() & e.ToString())) GoTo ContinueWhile1 End Try ContinueWhile1: End While Return returnCodeCode End Function 'CopyDemo ' ToXml creates an XML encoding of the permission and its current state; FromXml reconstructs a ' permission with the specified state from the XML encoding. Private Function ToFromXmlDemo() As Boolean Dim returnCodeCode As Boolean = True Dim site1 As [String] = "" Dim siteIdPerm1, siteIdPerm2 As SiteIdentityPermission Dim siteGen1 As New SiteGenerator() Dim siteGen2 As New SiteGenerator() siteGen1.ResetIndex() While siteGen1.CreateSite(site1) siteIdPerm1 = siteGen1.CreatePerm(site1) If siteIdPerm1 Is Nothing Then GoTo ContinueWhile1 End If siteGen2.ResetIndex() Console.WriteLine("**************************************************************************") Try siteIdPerm2 = New SiteIdentityPermission(PermissionState.None) siteIdPerm2.FromXml(siteIdPerm1.ToXml()) Dim result As Boolean = siteIdPerm2.Equals(siteIdPerm1) If siteIdPerm2.IsSubsetOf(siteIdPerm1) AndAlso siteIdPerm1.IsSubsetOf(siteIdPerm2) Then Console.WriteLine(("Result of ToFromXml = " & siteIdPerm2.ToString())) Else Console.WriteLine(siteIdPerm2.ToString()) Console.WriteLine(siteIdPerm1.ToString()) End If Catch e As Exception Console.WriteLine(("ToFromXml failed. " & e.ToString())) GoTo ContinueWhile1 End Try ContinueWhile1: End While Return returnCodeCode End Function 'ToFromXmlDemo ' Invoke all demos. Public Function RunDemo() As Boolean Dim returnCode As Boolean = True Dim tempReturnCode As Boolean ' Call the IsSubsetOf demo. tempReturnCode = IsSubsetOfDemo() If tempReturnCode Then Console.Out.WriteLine("The IsSubsetOf demo completed successfully.") Else Console.Out.WriteLine("subsetDemo failed.") End If returnCode = tempReturnCode AndAlso returnCode ' Call the Union demo. tempReturnCode = UnionDemo() If tempReturnCode Then Console.Out.WriteLine("The Union demo completed successfully.") Else Console.Out.WriteLine("UnionDemo failed.") End If returnCode = tempReturnCode AndAlso returnCode ' Call the Intersect demo. tempReturnCode = IntersectDemo() If tempReturnCode Then Console.Out.WriteLine("The Intersect demo completed successfully.") Else Console.Out.WriteLine("IntersectDemo failed.") End If returnCode = tempReturnCode AndAlso returnCode ' Call the Copy demo. tempReturnCode = CopyDemo() If tempReturnCode Then Console.Out.WriteLine("The Copy demo completed successfully.") Else Console.Out.WriteLine("CopyDemo failed.") End If returnCode = tempReturnCode AndAlso returnCode ' Call the ToFromXML demo. tempReturnCode = ToFromXmlDemo() If tempReturnCode Then Console.Out.WriteLine("The ToFromXML demo completed successfully.") Else Console.Out.WriteLine("ToFromXmlDemo failed.") End If returnCode = tempReturnCode AndAlso returnCode Return returnCode End Function 'RunDemo ' Test harness. Public Overloads Shared Sub Main(ByVal args() As [String]) Try Dim testcase As New SiteIdentityPermissionDemo() Dim returnCode As Boolean = testcase.RunDemo() If returnCode Then Console.Out.WriteLine("The SiteIdentityPermission demo completed successfully.") Console.Out.WriteLine("Press the Enter key to exit.") Dim consoleInput As String = Console.ReadLine() System.Environment.ExitCode = 100 Else Console.Out.WriteLine("The SiteIdentityPermission demo failed.") Console.Out.WriteLine("Press the Enter key to exit.") Dim consoleInput As String = Console.ReadLine() System.Environment.ExitCode = 101 End If Catch e As Exception Console.Out.WriteLine("The SiteIdentityPermission demo failed.") Console.WriteLine(e.ToString()) Console.Out.WriteLine("Press the Enter key to exit.") Dim consoleInput As String = Console.ReadLine() System.Environment.ExitCode = 101 End Try End Sub 'Main End Class 'SiteIdentityPermissionDemo ' This class generates SiteIdentityPermission objects. Friend Class SiteGenerator Private siteArray As String() = {"www.northwindtraders.northwindtraders.com", "*.northwindtraders.com", "*.margiestravel.com", "northwindtraders.com", "*northwindtraders.com", ""} ' Replace this array with Web sites of your own choosing. Private siteIndex As Integer = 0 Public Sub New() ResetIndex() End Sub 'New Public Sub ResetIndex() siteIndex = 0 End Sub 'ResetIndex ' CreateSite creates a SiteIdentityPermission. Public Function CreateSite(ByRef site As String) As Boolean If siteIndex >= siteArray.Length Then site = "null" Return False End If site = siteArray(siteIndex) siteIndex = siteIndex + 1 Return True End Function <System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Security", "CA2103")> _ Public Function CreatePerm(ByRef site As String) As SiteIdentityPermission Dim sitePerm As SiteIdentityPermission Try sitePerm = New SiteIdentityPermission(site) Return sitePerm Catch e As ArgumentException Console.WriteLine(("An ArgumentException was thrown: " & e.Message.ToString())) If Not (site Is Nothing) AndAlso site <> "" Then Console.WriteLine((site & " is an invalid site.")) ElseIf site = "" Then Console.WriteLine("An empty string signifies an invalid site.") site = "an empty string" End If Return Nothing End Try End Function 'CreateSite End Class 'SiteGenerator ' End of SiteGenerator.
// This sample demonstrates the IsSubsetOf, Union, Intersect, Copy, ToXml
// and FromXml methods
// of the SiteIdentityPermission class.
import System.*;
import System.Security.*;
import System.Security.Permissions.*;
/** @assembly CLSCompliant(true)
*/
public class SiteIdentityPermissionDemo
{
// IsSubsetOf determines whether the current permission is a subset of
// the specified permission.
private boolean IsSubsetOfDemo()
{
boolean returnCodeCode = true;
String site1[] = new String[1];
String site2[] = new String[1];
boolean successFlag[] = new boolean[1];
SiteIdentityPermission siteIdPerm1[] = new SiteIdentityPermission[1];
SiteIdentityPermission siteIdPerm2[] = new SiteIdentityPermission[1];
SiteGenerator siteGen1 = new SiteGenerator();
SiteGenerator siteGen2 = new SiteGenerator();
siteGen1.ResetIndex();
while (siteGen1.CreateSite(siteIdPerm1, site1, successFlag))
{
if (siteIdPerm1[0] == null | successFlag[0] == false) {
continue;
}
siteGen2.ResetIndex();
Console.WriteLine("**************************************"
+ "************************************");
while (siteGen2.CreateSite(siteIdPerm2, site2, successFlag)) {
try {
if (siteIdPerm2[0] == null | successFlag[0] == false) {
continue;
}
if (siteIdPerm1[0].IsSubsetOf(siteIdPerm2[0])) {
Console.WriteLine((site1[0] + " is a subset of "
+ site2[0]));
}
else {
Console.WriteLine((site1[0] + " is not a subset of "
+ site2[0]));
}
}
catch (Exception e)
{
Console.WriteLine(("An exception was thrown : " + e));
return false;
}
}
}
return returnCodeCode;
} //IsSubsetOfDemo
// Union creates a new permission that is the union of the current
// permission
// and the specified permission.
private boolean UnionDemo()
{
boolean returnCodeCode = true;
String site1[] = new String[1];
String site2[] = new String[1];
boolean successFlag[] = new boolean[1];
SiteIdentityPermission siteIdPerm1[] = new SiteIdentityPermission[1];
SiteIdentityPermission siteIdPerm2[] = new SiteIdentityPermission[1];
SiteIdentityPermission p3 = null;
SiteGenerator siteGen1 = new SiteGenerator();
SiteGenerator siteGen2 = new SiteGenerator();
siteGen1.ResetIndex();
while(siteGen1.CreateSite(siteIdPerm1, site1, successFlag)) {
if (siteIdPerm1[0] == null | successFlag[0] == false) {
continue ;
}
siteGen2.ResetIndex();
Console.WriteLine("****************************************"
+ "**********************************");
while(siteGen2.CreateSite(siteIdPerm2, site2, successFlag)) {
if (siteIdPerm2[0] == null | successFlag[0] == false) {
continue ;
}
String firstSite = (site1[0] == null) ? "null" : site1[0];
String secondSite = (site2[0] == null) ? "null" : site2[0];
try {
p3 =((SiteIdentityPermission)(
siteIdPerm1[0].Union(siteIdPerm2[0])));
String thirdSite = (p3.get_Site() == null) ?
"null" : p3.get_Site();
if (p3 != null) {
Console.WriteLine(("The union of " + firstSite
+ " and \n\t" + secondSite + " = \n\t"
+ thirdSite + "\n"));
}
else {
Console.WriteLine(("The union of " + firstSite
+ " and \n\t" + secondSite + " = null.\n"));
}
}
catch(Exception exp) {
// Expected exception, result of the union is null.
Console.WriteLine(("The union of " + firstSite
+ " and \n\t" + secondSite + " = null.\n"));
}
}
}
return returnCodeCode ;
}
// Intersect creates and returns a new permission that is the intersection
// of the current permission and the permission specified.
private boolean IntersectDemo()
{
boolean returnCodeCode = true;
String site1[] = new String[1];
String site2[] = new String[1];
boolean successFlag[] = new boolean[1];
SiteIdentityPermission siteIdPerm1[] = new SiteIdentityPermission[1];
SiteIdentityPermission siteIdPerm2[] = new SiteIdentityPermission[1];
SiteIdentityPermission p3 = null;
SiteGenerator siteGen1 = new SiteGenerator();
SiteGenerator siteGen2 = new SiteGenerator();
siteGen1.ResetIndex();
while(siteGen1.CreateSite(siteIdPerm1, site1, successFlag)) {
if (siteIdPerm1 == null | successFlag[0] == false) {
continue ;
}
siteGen2.ResetIndex();
Console.WriteLine("***************************************"
+ "***********************************");
while(siteGen2.CreateSite(siteIdPerm2, site2, successFlag)) {
if (siteIdPerm2[0] == null | successFlag[0] == false) {
continue ;
}
String firstSite = (site1[0] == null) ? "null" : site1[0];
String secondSite = (site2[0] == null) ? "null" : site2[0];
try {
p3 =((SiteIdentityPermission)(siteIdPerm1[0].
Intersect(siteIdPerm2[0])));
String thirdSite = (p3.get_Site() == null) ?
"null" : p3.get_Site();
if (p3 != null) {
Console.WriteLine(("The intersection of " + firstSite
+ " and \n\t" + secondSite + " = "
+ thirdSite + "\n"));
}
else {
Console.WriteLine(("The intersection of " + firstSite
+ " and \n\t" + secondSite + " = null.\n"));
}
}
catch(Exception exp) {
Console.WriteLine(("The intersection of " + firstSite
+ " and \n\t" + secondSite + " = null.\n"));
}
}
}
return returnCodeCode ;
} //IntersectDemo
//Copy creates and returns an identical copy of the current permission.
private boolean CopyDemo()
{
boolean returnCodeCode = true;
String site1[] = new String[1];
SiteIdentityPermission siteIdPerm1[] = new SiteIdentityPermission[1];
SiteIdentityPermission siteIdPerm2[] = new SiteIdentityPermission[1];
boolean successFlag[] = new boolean[1];
SiteGenerator siteGen1 = new SiteGenerator();
SiteGenerator siteGen2 = new SiteGenerator();
siteGen1.ResetIndex();
while(siteGen1.CreateSite(siteIdPerm1, site1, successFlag)) {
if (siteIdPerm1[0] == null | successFlag[0] == false) {
continue ;
}
siteGen2.ResetIndex();
Console.WriteLine("*********************************"
+ "*****************************************");
try {
siteIdPerm2[0] =((SiteIdentityPermission)(siteIdPerm1[0].Copy()));
if (siteIdPerm2 != null) {
Console.WriteLine(("The copy of "
+ siteIdPerm2[0].ToString() + " succeeded.\n"));
}
}
catch(Exception e) {
Console.WriteLine(("The copy failed : "
+ siteIdPerm1[0].ToString() + e));
continue ;
}
}
return returnCodeCode ;
} //CopyDemo
// ToXml creates an XML encoding of the permission and its current state;
// FromXml reconstructs a permission with the specified state from the
// XML encoding.
private boolean ToFromXmlDemo()
{
boolean returnCodeCode = true;
String site1[] = new String[1];
SiteIdentityPermission siteIdPerm1[] = new SiteIdentityPermission[1];
SiteIdentityPermission siteIdPerm2[] = new SiteIdentityPermission[1];
boolean successFlag[] = new boolean[1];
SiteGenerator siteGen1 = new SiteGenerator();
SiteGenerator siteGen2 = new SiteGenerator();
siteGen1.ResetIndex();
while(siteGen1.CreateSite(siteIdPerm1, site1, successFlag)) {
if (siteIdPerm1[0] == null | successFlag[0] == false) {
continue ;
}
siteGen2.ResetIndex();
Console.WriteLine("*********************************************"
+ "*****************************");
try {
siteIdPerm2[0] = new SiteIdentityPermission(PermissionState.None);
siteIdPerm2[0].FromXml(siteIdPerm1[0].ToXml());
boolean result = siteIdPerm2[0].Equals(siteIdPerm1[0]);
if (siteIdPerm2[0].IsSubsetOf(siteIdPerm1[0]) &&
siteIdPerm1[0].IsSubsetOf(siteIdPerm2[0])) {
Console.WriteLine(("Result of ToFromXml = "
+ siteIdPerm2[0].ToString()));
}
else {
Console.WriteLine(siteIdPerm2[0].ToString());
Console.WriteLine(siteIdPerm1[0].ToString());
}
}
catch(Exception e) {
Console.WriteLine(("ToFromXml failed. " + e));
continue ;
}
}
return returnCodeCode ;
} //ToFromXmlDemo
// Invoke all demos.
public boolean RunDemo()
{
boolean returnCode = true;
boolean tempReturnCode;
// Call the IsSubsetOf demo.
if (tempReturnCode = IsSubsetOfDemo()) {
Console.get_Out().WriteLine("The IsSubsetOf demo "
+ "completed successfully.");
}
else {
Console.get_Out().WriteLine("subsetDemo failed.");
}
returnCode = tempReturnCode && returnCode;
// Call the Union demo.
if (tempReturnCode = UnionDemo()) {
Console.get_Out().WriteLine(
"The Union demo completed successfully.");
}
else {
Console.get_Out().WriteLine("UnionDemo failed.");
}
returnCode = tempReturnCode && returnCode;
// Call the Intersect demo.
if (tempReturnCode = IntersectDemo()) {
Console.get_Out().WriteLine("The Intersect demo "
+ "completed successfully.");
}
else {
Console.get_Out().WriteLine("IntersectDemo failed.");
}
returnCode = tempReturnCode && returnCode;
// Call the Copy demo.
if (tempReturnCode = CopyDemo()) {
Console.get_Out().WriteLine("The Copy demo completed successfully.");
}
else {
Console.get_Out().WriteLine("CopyDemo failed.");
}
returnCode = tempReturnCode && returnCode;
// Call the ToFromXML demo.
if (tempReturnCode = ToFromXmlDemo()) {
Console.get_Out().WriteLine("The ToFromXML demo "
+ "completed successfully.");
}
else {
Console.get_Out().WriteLine("ToFromXmlDemo failed.");
}
returnCode = tempReturnCode && returnCode;
return returnCode ;
} //RunDemo
// Test harness.
public static void main(String[] args)
{
try {
SiteIdentityPermissionDemo testcase =
new SiteIdentityPermissionDemo();
boolean returnCode = testcase.RunDemo();
if (returnCode) {
Console.get_Out().WriteLine("The SiteIdentityPermission "
+ "demo completed successfully.");
Console.get_Out().WriteLine("Press the Enter key to exit.");
String consoleInput = Console.ReadLine();
Environment.set_ExitCode(100);
}
else {
Console.get_Out().WriteLine("The SiteIdentityPermission "
+ "demo failed.");
Console.get_Out().WriteLine("Press the Enter key to exit.");
String consoleInput = Console.ReadLine();
Environment.set_ExitCode(101);
}
}
catch(Exception e) {
Console.get_Out().WriteLine("The SiteIdentityPermission "
+ "demo failed.");
Console.WriteLine(e.ToString());
Console.get_Out().WriteLine("Press the Enter key to exit.");
String consoleInput = Console.ReadLine();
Environment.set_ExitCode(101);
}
} //main
} //SiteIdentityPermissionDemo
// This class generates SiteIdentityPermission objects.
class SiteGenerator
{
private String siteArray[] = {"www.northwindtraders.northwindtraders.com",
"*.northwindtraders.com", "*.margiestravel.com", "northwindtraders.com",
"*northwindtraders.com", ""};
// Replace this array with Web sites of your own choosing.
private int siteIndex = 0;
public SiteGenerator()
{
ResetIndex();
} //SiteGenerator
public void ResetIndex()
{
siteIndex = 0;
} //ResetIndex
// CreateSite creates a SiteIdentityPermission.
public boolean CreateSite(SiteIdentityPermission sitePerm[],
String site[], boolean successFlag[])
{
successFlag[0] = true;
if (siteIndex >= siteArray.length) {
sitePerm[0] = new SiteIdentityPermission(PermissionState.None);
site[0] = "null";
return false ;
}
site[0] = siteArray[siteIndex++];
try {
sitePerm[0] = new SiteIdentityPermission(site[0]);
return true ;
}
catch(ArgumentException e) {
Console.WriteLine(("An ArgumentException was thrown: "
+ e.get_Message()));
successFlag[0] = false;
if (site[0] != null && site[0] != "") {
Console.WriteLine((site[0] + " is an invalid site."));
}
else {
if (site[0].equalsIgnoreCase("") == true) {
Console.WriteLine("An empty string signifies "
+ "an invalid site.");
site[0] = "an empty string";
}
else {
sitePerm[0] =
new SiteIdentityPermission(PermissionState.None);
Console.WriteLine(e);
site[0] = "null";
return false ;
}
}
sitePerm[0] = new SiteIdentityPermission(PermissionState.None);
return true ;
}
} //CreateSite
} //SiteGenerator
System.Security.CodeAccessPermission
System.Security.Permissions.SiteIdentityPermission
Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.
Caution