SiteIdentityPermission 类
为作为代码来源地的网站定义标识权限。无法继承此类。
**命名空间:**System.Security.Permissions
**程序集:**mscorlib(在 mscorlib.dll 中)
语法
声明
<SerializableAttribute> _
<ComVisibleAttribute(True)> _
Public NotInheritable Class SiteIdentityPermission
Inherits CodeAccessPermission
用法
Dim instance As SiteIdentityPermission
[SerializableAttribute]
[ComVisibleAttribute(true)]
public sealed class SiteIdentityPermission : CodeAccessPermission
[SerializableAttribute]
[ComVisibleAttribute(true)]
public ref class SiteIdentityPermission sealed : public CodeAccessPermission
/** @attribute SerializableAttribute() */
/** @attribute ComVisibleAttribute(true) */
public final class SiteIdentityPermission extends CodeAccessPermission
SerializableAttribute
ComVisibleAttribute(true)
public final class SiteIdentityPermission extends CodeAccessPermission
备注
使用该类可以确保调用方来自某特定网站。仅为来自带有 HTTP、HTTPS 和 FTP 协议的 URL 的代码定义站点标识。站点是 URL 的协议后面的“//”和之后的“/”(如果有)之间的字符串,例如 URL https://www.fourthcoffee.com/process/grind.htm 中的 www.fourthcoffee.com。其中不包括端口号。如果给定的 URL 是 https://www.fourthcoffee.com:8000/,则站点为 www.fourthcoffee.com,而非 www.fourthcoffee.com:8000。
站点可以完全匹配,也可以通过在点分隔符位置使用通配符(“*”)前缀进行匹配。例如,站点名称字符串 *.fourthcoffee.com 与 fourthcoffee.com 和 www.fourthcoffee.com 匹配。如果没有通配符,则站点名称必须是精确匹配。站点名称字符串 * 将与所有站点匹配,但不会与无站点证据的代码匹配。
警告
SiteIdentityPermission 将所有路径的权限授予给该站点,包括 URL 与 IP 地址。若要 Deny 对站点的访问,则必须 Deny 该站点所有可能的路径。例如,如果 www.fourthcoffee.com 的 IP 地址为 192.168.238.241,若要 Deny 对 www.fourthcoffee.com 的访问,则必须 Deny www.fourthcoffee.com、192.168.238.241 以及其他任何可用于访问该站点的路径。处理多路径的更好方法是结合使用 PermitOnly 和 Deny。有关此主题以及结合使用 PermitOnly 和 Deny 的更多信息,请参见 使用 Deny 方法 主题中的 Canonicalization Problems Using Deny。
提示
在 .NET Framework 1.0 和 1.1 版中,标识权限不能具有 Unrestricted 权限状态值。在 .NET Framework 2.0 版中,标识权限可以具有任何权限状态值。这意味着在 2.0 版中,标识权限与实现 IUnrestrictedPermission 接口的权限具有相同的行为。有关使用 1.1 版 CAS 策略执行 2.0 版应用程序的信息,请参见 <legacyV1CASPolicy> 元素。
示例
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.
using System;
using System.Security;
using System.Security.Permissions;
[assembly: CLSCompliant(true)]
public class SiteIdentityPermissionDemo
{
// IsSubsetOf determines whether the current permission is a subset of the specified permission.
private bool IsSubsetOfDemo()
{
bool returnCodeCode = true;
String site1, site2;
SiteIdentityPermission siteIdPerm1, siteIdPerm2;
SiteGenerator siteGen1 = new SiteGenerator();
SiteGenerator siteGen2 = new SiteGenerator();
siteGen1.ResetIndex();
while (siteGen1.CreateSite(out site1))
{
siteIdPerm1 = siteGen1.CreatePerm(site1);
if (siteIdPerm1 == null ) continue;
siteGen2.ResetIndex();
Console.WriteLine("**************************************************************************");
while (siteGen2.CreateSite(out site2))
{
try
{
siteIdPerm2 = siteGen2.CreatePerm(site2);
if (siteIdPerm2 == null ) continue;
if (siteIdPerm1.IsSubsetOf(siteIdPerm2))
{
Console.WriteLine(site1 + " is a subset of " + site2);
}
else
{
Console.WriteLine(site1 + " is not a subset of " + site2);
}
}
catch (Exception e)
{
Console.WriteLine("An exception was thrown : " + e);
return false;
}
}
}
return returnCodeCode;
}
// Union creates a new permission that is the union of the current permission
// and the specified permission.
private bool UnionDemo()
{
bool returnCodeCode = true;
String site1, site2;
SiteIdentityPermission siteIdPerm1, siteIdPerm2, p3;
SiteGenerator siteGen1 = new SiteGenerator();
SiteGenerator siteGen2 = new SiteGenerator();
siteGen1.ResetIndex();
while (siteGen1.CreateSite(out site1))
{
siteIdPerm1 = siteGen1.CreatePerm(site1);
if (siteIdPerm1 == null ) continue;
siteGen2.ResetIndex();
Console.WriteLine("**************************************************************************");
while (siteGen2.CreateSite(out site2))
{
siteIdPerm2 = siteGen2.CreatePerm(site2);
if (siteIdPerm2 == null ) continue;
String firstSite = site1 == null ? "null" : site1;
String secondSite = site2 == null ? "null" : site2;
try
{
p3 = (SiteIdentityPermission)siteIdPerm1.Union(siteIdPerm2);
String thirdSite = p3.Site == null ? "null" : p3.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 e)
{
// Expected exception.
Console.WriteLine(e.Message + "\n\t" + firstSite + " and " + secondSite + "\n");
}
}
}
return returnCodeCode;
}
// Intersect creates and returns a new permission that is the intersection of the
// current permission and the permission specified.
private bool IntersectDemo()
{
bool returnCodeCode = true;
String site1, site2;
SiteIdentityPermission siteIdPerm1, siteIdPerm2, p3;
SiteGenerator siteGen1 = new SiteGenerator();
SiteGenerator siteGen2 = new SiteGenerator();
siteGen1.ResetIndex();
while (siteGen1.CreateSite(out site1))
{
siteIdPerm1 = siteGen1.CreatePerm(site1);
if (siteIdPerm1 == null ) continue;
siteGen2.ResetIndex();
Console.WriteLine("**************************************************************************");
while (siteGen2.CreateSite(out site2))
{
siteIdPerm2 = siteGen2.CreatePerm(site2);
if (siteIdPerm2 == null ) continue;
String firstSite = site1 == null ? "null" : site1;
String secondSite = site2 == null ? "null" : site2;
try
{
p3 = (SiteIdentityPermission)siteIdPerm1.Intersect(siteIdPerm2);
String thirdSite = p3.Site == null ? "null" : p3.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
{
Console.WriteLine("The intersection of " + firstSite + " and \n\t" + secondSite + " = null.\n");
}
}
}
return returnCodeCode;
}
//Copy creates and returns an identical copy of the current permission.
private bool CopyDemo()
{
bool returnCodeCode = true;
String site1;
SiteIdentityPermission siteIdPerm1, siteIdPerm2;
SiteGenerator siteGen1 = new SiteGenerator();
SiteGenerator siteGen2 = new SiteGenerator();
siteGen1.ResetIndex();
while (siteGen1.CreateSite(out site1))
{
siteIdPerm1 = siteGen1.CreatePerm(site1);
if (siteIdPerm1 == null ) continue;
siteGen2.ResetIndex();
Console.WriteLine("**************************************************************************");
try
{
siteIdPerm2 = (SiteIdentityPermission)siteIdPerm1.Copy();
if (siteIdPerm2 != null)
{
Console.WriteLine("The copy of " + siteIdPerm2.ToString() + " succeeded.\n");
}
}
catch (Exception e)
{
Console.WriteLine("The copy failed : " + siteIdPerm1.ToString() + e);
continue;
}
}
return returnCodeCode;
}
// 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 bool ToFromXmlDemo()
{
bool returnCodeCode = true;
String site1;
SiteIdentityPermission siteIdPerm1, siteIdPerm2;
SiteGenerator siteGen1 = new SiteGenerator();
SiteGenerator siteGen2 = new SiteGenerator();
siteGen1.ResetIndex();
while (siteGen1.CreateSite(out site1))
{
siteIdPerm1 = siteGen1.CreatePerm(site1);
if (siteIdPerm1 == null ) continue;
siteGen2.ResetIndex();
Console.WriteLine("**************************************************************************");
try
{
siteIdPerm2 = new SiteIdentityPermission(PermissionState.None);
siteIdPerm2.FromXml(siteIdPerm1.ToXml());
bool result = siteIdPerm2.Equals(siteIdPerm1);
if (siteIdPerm2.IsSubsetOf(siteIdPerm1) && siteIdPerm1.IsSubsetOf(siteIdPerm2))
{
Console.WriteLine("Result of ToFromXml = " + siteIdPerm2.ToString());
}
else
{
Console.WriteLine(siteIdPerm2.ToString());
Console.WriteLine(siteIdPerm1.ToString());
}
}
catch (Exception e)
{
Console.WriteLine("ToFromXml failed. " + e);
continue;
}
}
return returnCodeCode;
}
// Invoke all demos.
public bool RunDemo()
{
bool returnCode = true;
bool tempReturnCode;
// Call the IsSubsetOf demo.
if (tempReturnCode = IsSubsetOfDemo()) Console.Out.WriteLine("The IsSubsetOf demo completed successfully.");
else
Console.Out.WriteLine("subsetDemo failed.");
returnCode = tempReturnCode && returnCode;
// Call the Union demo.
if (tempReturnCode = UnionDemo()) Console.Out.WriteLine("The Union demo completed successfully.");
else
Console.Out.WriteLine("UnionDemo failed.");
returnCode = tempReturnCode && returnCode;
// Call the Intersect demo.
if (tempReturnCode = IntersectDemo()) Console.Out.WriteLine("The Intersect demo completed successfully.");
else
Console.Out.WriteLine("IntersectDemo failed.");
returnCode = tempReturnCode && returnCode;
// Call the Copy demo.
if (tempReturnCode = CopyDemo()) Console.Out.WriteLine("The Copy demo completed successfully.");
else
Console.Out.WriteLine("CopyDemo failed.");
returnCode = tempReturnCode && returnCode;
// Call the ToFromXML demo.
if (tempReturnCode = ToFromXmlDemo()) Console.Out.WriteLine("The ToFromXML demo completed successfully.");
else
Console.Out.WriteLine("ToFromXmlDemo failed.");
returnCode = tempReturnCode && returnCode;
return (returnCode);
}
// Test harness.
public static void Main(String[] args)
{
try
{
SiteIdentityPermissionDemo testcase = new SiteIdentityPermissionDemo();
bool returnCode = testcase.RunDemo();
if (returnCode)
{
Console.Out.WriteLine("The SiteIdentityPermission demo completed successfully.");
Console.Out.WriteLine("Press the Enter key to exit.");
string consoleInput = Console.ReadLine();
System.Environment.ExitCode = 100;
}
else
{
Console.Out.WriteLine("The SiteIdentityPermission demo failed.");
Console.Out.WriteLine("Press the Enter key to exit.");
string consoleInput = Console.ReadLine();
System.Environment.ExitCode = 101;
}
}
catch (Exception e)
{
Console.Out.WriteLine("The SiteIdentityPermission demo failed.");
Console.WriteLine(e.ToString());
Console.Out.WriteLine("Press the Enter key to exit.");
string consoleInput = Console.ReadLine();
System.Environment.ExitCode = 101;
}
}
}
// This class generates SiteIdentityPermission objects.
internal class SiteGenerator
{
private string[] siteArray =
// Replace this array with Web sites of your own choosing.
{
"www.fourthcoffee.com",
"www.tailspintoys.com",
"*.fourthcoffee.com",
"*.com",
""};
private int siteIndex = 0;
public SiteGenerator()
{
ResetIndex();
}
public void ResetIndex()
{
siteIndex = 0;
}
// CreateSite creates a SiteIdentityPermission.
public bool CreateSite(out string site)
{
if (siteIndex >= siteArray.Length)
{
site = "null";
return false;
}
site = siteArray[siteIndex++];
return true;
}
public SiteIdentityPermission CreatePerm(string site)
{
SiteIdentityPermission sitePerm;
try
{
string newSite = site;
sitePerm = new SiteIdentityPermission(newSite);
return sitePerm;
}
catch (ArgumentException e)
{
Console.WriteLine("An ArgumentException was thrown: " + e.Message);
if (site != null && site != "")
{
Console.WriteLine(site + " is an invalid site.");
}
else if (site == "")
{
Console.WriteLine("An empty string signifies an invalid site.");
site = "an empty string";
}
return null;
}
}
} // End of SiteGenerator.
using namespace System;
using namespace System::Security;
using namespace System::Security::Permissions;
using namespace System::Runtime::InteropServices;
// This class generates SiteIdentityPermission objects.
[assembly:CLSCompliant(true)];
private ref class SiteGenerator
{
private:
array<String^>^siteArray;
int siteIndex;
public:
SiteGenerator()
{
// Replace this array with Web sites of your own choosing.
array<String^>^temp = {"www.northwindtraders.northwindtraders.com","*.northwindtraders.com","*.margiestravel.com","northwindtraders.com","*northwindtraders.com",""};
siteArray = temp;
ResetIndex();
}
void ResetIndex()
{
siteIndex = 0;
}
// CreateSite creates a SiteIdentityPermission.
bool CreateSite( [Out]interior_ptr<String^> site )
{
if ( siteIndex >= siteArray->Length )
{
*site = "null";
return false;
}
*site = siteArray[ siteIndex++ ];
return true;
}
[System::Diagnostics::CodeAnalysis::SuppressMessageAttribute("Microsoft.Security", "CA2103")]
SiteIdentityPermission^ CreatePerm( [In]interior_ptr<String^> site)
{
try
{
SiteIdentityPermission^ sitePerm = gcnew SiteIdentityPermission( *site );
return sitePerm;
}
catch ( ArgumentException^ e )
{
Console::WriteLine( "An ArgumentException was thrown: {0}", e->Message );
if ( *site != nullptr && !( *site)->Equals( "" ) )
{
Console::WriteLine( "{0} is an invalid site.", *site );
}
else
if ( ( *site)->Equals( "" ) )
{
Console::WriteLine( "An empty string signifies an invalid site." );
*site = "an empty string";
}
return nullptr;
}
}
};
// End of SiteGenerator.
public ref class SiteIdentityPermissionDemo
{
private:
// IsSubsetOf determines whether the current permission is a subset of the specified permission.
bool IsSubsetOfDemo()
{
bool returnCodeCode = true;
String^ site1;
String^ site2;
SiteIdentityPermission^ siteIdPerm1;
SiteIdentityPermission^ siteIdPerm2;
SiteGenerator^ siteGen1 = gcnew SiteGenerator;
SiteGenerator^ siteGen2 = gcnew SiteGenerator;
siteGen1->ResetIndex();
while ( siteGen1->CreateSite( &site1 ) )
{
siteIdPerm1 = siteGen1->CreatePerm(&site1);
if ( siteIdPerm1 == nullptr )
continue;
siteGen2->ResetIndex();
Console::WriteLine( "**************************************************************************" );
while ( siteGen2->CreateSite( &site2 ) )
{
siteIdPerm2 = siteGen1->CreatePerm(&site2);
try
{
if ( siteIdPerm2 == nullptr )
continue;
if ( siteIdPerm1->IsSubsetOf( siteIdPerm2 ) )
{
Console::WriteLine( "{0} is a subset of {1}", site1, site2 );
}
else
{
Console::WriteLine( "{0} is not a subset of {1}", site1, site2 );
}
}
catch ( Exception^ e )
{
Console::WriteLine( "An exception was thrown : {0}", e );
return false;
}
}
}
return returnCodeCode;
}
// Union creates a new permission that is the union of the current permission
// and the specified permission.
bool UnionDemo()
{
bool returnCodeCode = true;
String^ site1;
String^ site2;
SiteIdentityPermission^ siteIdPerm1;
SiteIdentityPermission^ siteIdPerm2;
SiteIdentityPermission^ p3;
SiteGenerator^ siteGen1 = gcnew SiteGenerator;
SiteGenerator^ siteGen2 = gcnew SiteGenerator;
siteGen1->ResetIndex();
while ( siteGen1->CreateSite( &site1 ) )
{
siteIdPerm1 = siteGen1->CreatePerm(&site1);
if ( siteIdPerm1 == nullptr )
continue;
siteGen2->ResetIndex();
Console::WriteLine( "**************************************************************************" );
while ( siteGen2->CreateSite( &site2 ) )
{
siteIdPerm2 = siteGen2->CreatePerm(&site2);
if ( siteIdPerm2 == nullptr )
continue;
String^ firstSite = site1 == nullptr ? "null" : site1;
String^ secondSite = site2 == nullptr ? "null" : site2;
try
{
p3 = dynamic_cast<SiteIdentityPermission^>(siteIdPerm1->Union( siteIdPerm2 ));
String^ thirdSite = p3->Site == nullptr ? "null" : p3->Site;
if ( p3 != nullptr )
{
Console::WriteLine( "The union of {0} and \n\t{1} = \n\t{2}\n", firstSite, secondSite, thirdSite );
}
else
{
Console::WriteLine( "The union of {0} and \n\t{1} = null.\n", firstSite, secondSite );
}
}
catch ( Exception^ )
{
// Expected exception, result of the union is 0.
Console::WriteLine( "The union of {0} and \n\t{1} = null.\n", firstSite, secondSite );
}
}
}
return returnCodeCode;
}
// Intersect creates and returns a new permission that is the intersection of the
// current permission and the permission specified.
bool IntersectDemo()
{
bool returnCodeCode = true;
String^ site1;
String^ site2;
SiteIdentityPermission^ siteIdPerm1;
SiteIdentityPermission^ siteIdPerm2;
SiteIdentityPermission^ p3;
SiteGenerator^ siteGen1 = gcnew SiteGenerator;
SiteGenerator^ siteGen2 = gcnew SiteGenerator;
siteGen1->ResetIndex();
while ( siteGen1->CreateSite( &site1 ) )
{
siteIdPerm1 = siteGen1->CreatePerm(&site1);
if ( siteIdPerm1 == nullptr )
continue;
siteGen2->ResetIndex();
Console::WriteLine( "**************************************************************************" );
while ( siteGen2->CreateSite( &site2 ) )
{
siteIdPerm2 = siteGen2->CreatePerm(&site2);
if ( siteIdPerm2 == nullptr )
continue;
String^ firstSite = site1 == nullptr ? "0" : site1;
String^ secondSite = site2 == nullptr ? "0" : site2;
try
{
p3 = dynamic_cast<SiteIdentityPermission^>(siteIdPerm1->Intersect( siteIdPerm2 ));
String^ thirdSite = p3->Site == nullptr ? "0" : p3->Site;
if ( p3 != nullptr )
{
Console::WriteLine( "The intersection of {0} and \n\t{1} = {2}\n", firstSite, secondSite, thirdSite );
}
else
{
Console::WriteLine( "The intersection of {0} and \n\t{1} = null.\n", firstSite, secondSite );
}
}
catch ( Exception^ )
{
Console::WriteLine( "The intersection of {0} and \n\t{1} = null.\n", firstSite, secondSite );
}
}
}
return returnCodeCode;
}
//Copy creates and returns an identical copy of the current permission.
bool CopyDemo()
{
bool returnCodeCode = true;
String^ site1;
SiteIdentityPermission^ siteIdPerm1;
SiteIdentityPermission^ siteIdPerm2;
SiteGenerator^ siteGen1 = gcnew SiteGenerator;
SiteGenerator^ siteGen2 = gcnew SiteGenerator;
siteGen1->ResetIndex();
while ( siteGen1->CreateSite( &site1 ) )
{
siteIdPerm1 = siteGen1->CreatePerm(&site1);
if ( siteIdPerm1 == nullptr )
continue;
siteGen2->ResetIndex();
Console::WriteLine( "**************************************************************************" );
try
{
siteIdPerm2 = dynamic_cast<SiteIdentityPermission^>(siteIdPerm1->Copy());
if ( siteIdPerm2 != nullptr )
{
Console::WriteLine( "The copy of {0} succeeded.\n", siteIdPerm2 );
}
}
catch ( Exception^ e )
{
Console::WriteLine( "The copy failed : {0}{1}", siteIdPerm1, e );
continue;
}
}
return returnCodeCode;
}
// ToXml creates an XML encoding of the permission and its current state; FromXml reconstructs a
// permission with the specified state from the XML encoding.
bool ToFromXmlDemo()
{
bool returnCodeCode = true;
String^ site1;
SiteIdentityPermission^ siteIdPerm1;
SiteIdentityPermission^ siteIdPerm2;
SiteGenerator^ siteGen1 = gcnew SiteGenerator;
SiteGenerator^ siteGen2 = gcnew SiteGenerator;
siteGen1->ResetIndex();
while ( siteGen1->CreateSite( &site1 ) )
{
siteIdPerm1 = siteGen1->CreatePerm(&site1);
if ( siteIdPerm1 == nullptr )
continue;
siteGen2->ResetIndex();
Console::WriteLine( "**************************************************************************" );
try
{
siteIdPerm2 = gcnew SiteIdentityPermission( PermissionState::None );
siteIdPerm2->FromXml( siteIdPerm1->ToXml() );
bool result = siteIdPerm2->Equals( siteIdPerm1 );
if ( siteIdPerm2->IsSubsetOf( siteIdPerm1 ) && siteIdPerm1->IsSubsetOf( siteIdPerm2 ) )
{
Console::WriteLine( "Result of ToFromXml = {0}", siteIdPerm2 );
}
else
{
Console::WriteLine( siteIdPerm2 );
Console::WriteLine( siteIdPerm1 );
}
}
catch ( Exception^ e )
{
Console::WriteLine( "ToFromXml failed. {0}", e );
continue;
}
}
return returnCodeCode;
}
public:
// Invoke all demos.
bool RunDemo()
{
bool returnCode = true;
bool tempReturnCode;
// Call the IsSubsetOf demo.
if ( tempReturnCode = IsSubsetOfDemo() )
Console::WriteLine( "The IsSubsetOf demo completed successfully." );
else
Console::WriteLine( "subsetDemo failed." );
returnCode = tempReturnCode && returnCode;
// Call the Union demo.
if ( tempReturnCode = UnionDemo() )
Console::WriteLine( "The Union demo completed successfully." );
else
Console::WriteLine( "UnionDemo failed." );
returnCode = tempReturnCode && returnCode;
// Call the Intersect demo.
if ( tempReturnCode = IntersectDemo() )
Console::WriteLine( "The Intersect demo completed successfully." );
else
Console::WriteLine( "IntersectDemo failed." );
returnCode = tempReturnCode && returnCode;
// Call the Copy demo.
if ( tempReturnCode = CopyDemo() )
Console::WriteLine( "The Copy demo completed successfully." );
else
Console::WriteLine( "CopyDemo failed." );
returnCode = tempReturnCode && returnCode;
// Call the ToFromXML demo.
if ( tempReturnCode = ToFromXmlDemo() )
Console::WriteLine( "The ToFromXML demo completed successfully." );
else
Console::WriteLine( "ToFromXmlDemo failed." );
returnCode = tempReturnCode && returnCode;
return (returnCode);
}
};
// Test harness.
int main()
{
try
{
SiteIdentityPermissionDemo^ testcase = gcnew SiteIdentityPermissionDemo;
bool returnCode = testcase->RunDemo();
if ( returnCode )
{
Console::WriteLine( "The SiteIdentityPermission demo completed successfully." );
Console::WriteLine( "Press the Enter key to exit." );
Console::ReadLine();
System::Environment::ExitCode = 100;
}
else
{
Console::WriteLine( "The SiteIdentityPermission demo failed." );
Console::WriteLine( "Press the Enter key to exit." );
Console::ReadLine();
System::Environment::ExitCode = 101;
}
}
catch ( Exception^ e )
{
Console::WriteLine( "The SiteIdentityPermission demo failed." );
Console::WriteLine( e );
Console::WriteLine( "Press the Enter key to exit." );
Console::ReadLine();
System::Environment::ExitCode = 101;
}
}
// 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.Object
System.Security.CodeAccessPermission
System.Security.Permissions.SiteIdentityPermission
线程安全
此类型的任何公共静态(Visual Basic 中的 Shared)成员都是线程安全的,但不保证所有实例成员都是线程安全的。
平台
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
.NET Framework 并不是对每个平台的所有版本都提供支持。有关受支持版本的列表,请参见系统要求。
版本信息
.NET Framework
受以下版本支持:2.0、1.1、1.0
请参见
参考
SiteIdentityPermission 成员
System.Security.Permissions 命名空间
SiteIdentityPermissionAttribute
Site
SiteMembershipCondition