Freigeben über


HttpModuleCollection.CopyTo-Methode

Kopiert Member der Modulauflistung in ein Array, beginnend am angegebenen Index des Arrays.

Namespace: System.Web
Assembly: System.Web (in system.web.dll)

Syntax

'Declaration
Public Sub CopyTo ( _
    dest As Array, _
    index As Integer _
)
'Usage
Dim instance As HttpModuleCollection
Dim dest As Array
Dim index As Integer

instance.CopyTo(dest, index)
public void CopyTo (
    Array dest,
    int index
)
public:
void CopyTo (
    Array^ dest, 
    int index
)
public void CopyTo (
    Array dest, 
    int index
)
public function CopyTo (
    dest : Array, 
    index : int
)

Parameter

  • index
    Der Index des Ziel-Array, an dem der Kopiervorgang gestartet wird.

Beispiel

Im folgenden Codebeispiel wird die AllKeys-Eigenschaft sowie die GetKey-Methode und die CopyTo-Methode der HttpModuleCollection-Klasse veranschaulicht. Das Beispiel ruft das Anwendungsobjekt für die aktuelle Anforderung aus dem aktuellen HttpContext-Objekt ab. Anschließend wird das HttpModuleCollection-Objekt aus der Anwendungsinstanz extrahiert, und die Namen der IHttpModule-Objekte werden angezeigt.

<%@ Page language="VB" %>
<%@ Import Namespace = "System.Data"  %>
<HTML>
<HEAD>

<script runat="server">
' System.Web.HttpModuleCollection.AllKeys;GetKey;CopyTo
Sub Page_Load(Sender As Object, e As EventArgs )

' Get the HttpContext object for the current request.
Dim i As Integer
Dim myHttpContext As HttpContext  = HttpContext.Current
' Get the application object for the current request.
Dim  myHttpApplication As HttpApplication = myHttpContext.ApplicationInstance
' Get the collection of all HTTPModule objects for the current application.
Dim myHttpModuleCollection As HttpModuleCollection = myHttpApplication.Modules
       
' Get the name of the HttpModule object at index 1.
Dim httpModuleName As string = myHttpModuleCollection.GetKey(1)
Response.Write("The name of the HttpModule object at index 1" + " is " +"'"+  httpModuleName+"'." + "<br><br>")
      
Dim  allModules() As string = myHttpModuleCollection.AllKeys
      
' Display the names of all HttpModule objects.
Response.Write("<b>The HttpModule objects of HttpModuleCollection are:</b><br>")

For i = 0 To allModules.Length -1 
   Response.Write("Module" + i.ToString() + "  : " + allModules(i).ToString() + "<br>")
Next i


' Copy the HttpModule objects in the collection into an array.    
Dim httpModuleArray As System.Array = Array.CreateInstance(GetType(object),myHttpModuleCollection.AllKeys.Length)
myHttpModuleCollection.CopyTo(httpModuleArray,0)
Response.Write("<br><br><b>Successfully copied the HttpModule objects in the HttpModuleCollection to an array."+ "<br>Displaying the HttpModule objects in the array:</b><br>")

For i=0 To httpModuleArray.Length -1
   Response.Write("Module" + i.ToString() + ": " + httpModuleArray.GetValue(i).ToString() + "<br>")
Next i

End Sub
</script>
</HEAD>
</HTML>
<%@ Page language="C#" %>
<%@ Import Namespace = "System.Data"  %>
<HTML>
<HEAD>
<script runat="server">
// System.Web.HttpModuleCollection.AllKeys;GetKey;CopyTo

void Page_Load(object sender, System.EventArgs e)
{
    // Get the HttpContext object for the current request.
    HttpContext myHttpContext = HttpContext.Current;
    // Get the application object for the current request.
    HttpApplication myHttpApplication = myHttpContext.ApplicationInstance;
    // Get the collection of all HTTPModule objects for the current application.
    HttpModuleCollection myHttpModuleCollection = myHttpApplication.Modules;

    // Get the name of the HttpModule object at index 1.
    string httpModuleName = myHttpModuleCollection.GetKey(1);
    Response.Write("The name of the HttpModule object at index 1" + " is " +"'"+  httpModuleName+"'." + "<br><br>"); 

    string[] allModules = myHttpModuleCollection.AllKeys;

    // Display the names of all HttpModule objects.
    Response.Write("<b>The HttpModule objects contained in the HttpModuleCollection are:</b><br>");

    for(int i=0; i < allModules.Length; i++)
       Response.Write("Module" + i + "  : " + allModules[i] + "<br>");

    // Copy the HttpModule objects in the collection into an array.
    System.Array httpModuleArray = Array.CreateInstance(typeof(object),myHttpModuleCollection.AllKeys.Length);
    myHttpModuleCollection.CopyTo(httpModuleArray,0);
    Response.Write("<br><br><b>Successfully copied the HttpModule objects in the HttpModuleCollection to an array."+
       "<br>Displaying the HttpModule objects in array:</b><br>");

    for(int i=0; i < httpModuleArray.Length; i++)
       Response.Write("Module" + i + ": " + httpModuleArray.GetValue(i) + "<br>");

}
</script>
</HEAD>
</HTML>
<%@ Page language="VJ#" %>
<%@ Import Namespace = "System.Data"  %>
<HTML>
<HEAD>
<script runat="server">
// System.Web.HttpModuleCollection.AllKeys;GetKey;CopyTo

void Page_Load(Object sender, System.EventArgs e)
{
    // The following example demonstrates the AllKeys property and the GetKey and
    // CopyTo methods of the HttpModuleCollection class. The example gets the 
    // application object for the current request from the current HttpContext 
    // object. It then extracts the HttpModuleCollection object from the 
    // application instance and displays the names of the HttpModule objects.


    // Get the HttpContext object for the current request.
    HttpContext myHttpContext = HttpContext.get_Current();
    // Get the application object for the current request.
    HttpApplication myHttpApplication = myHttpContext.get_ApplicationInstance();
    // Get the collection of all HTTPModule objects for the current application.
    HttpModuleCollection myHttpModuleCollection = 
        myHttpApplication.get_Modules();
           
    // Get the name of the HttpModule object at index 1.
    String httpModuleName = myHttpModuleCollection.GetKey(1);
    get_Response().Write("The name of the HttpModule object at index 1" 
        + " is " +"'"+  httpModuleName+"'." + "<br><br>"); 
          
    String allModules[] = myHttpModuleCollection.get_AllKeys();
          
    // Display the names of all HttpModule objects.
    get_Response().Write("<b>The HttpModule objects contained in the " 
        + "HttpModuleCollection are:</b><br>");
    for(int i=0; i < allModules.get_Length(); i++) {
        get_Response().Write("Module" + i + "  : " 
            + allModules[i] + "<br>");
    }

    // Copy the HttpModule objects in the collection into an array.
    System.Array httpModuleArray = Array.CreateInstance(Object.class.ToType(),
        myHttpModuleCollection.get_AllKeys().get_Length());
    myHttpModuleCollection.CopyTo(httpModuleArray,0);
    
    get_Response().Write("<br><br><b>Successfully copied the HttpModule " 
        + "objects in the HttpModuleCollection to an array."
        + "<br>Displaying the HttpModule objects in array:</b><br>");
    
    for(int i=0; i < httpModuleArray.get_Length(); i++) {
        get_Response().Write("Module" + i + ": " + httpModuleArray.GetValue(i) 
            + "<br>");
    }
} // Page_Load
</script>
</HEAD>
</HTML>

Plattformen

Windows 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

.NET Framework unterstützt nicht alle Versionen sämtlicher Plattformen. Eine Liste der unterstützten Versionen finden Sie unter Systemanforderungen.

Versionsinformationen

.NET Framework

Unterstützt in: 2.0, 1.1, 1.0

Siehe auch

Referenz

HttpModuleCollection-Klasse
HttpModuleCollection-Member
System.Web-Namespace