HttpResponse.AddFileDependencies HttpResponse.AddFileDependencies HttpResponse.AddFileDependencies HttpResponse.AddFileDependencies Method

Definition

Fügt der Auflistung der Dateinamen, von denen die aktuelle Antwort abhängt, eine Gruppe von Dateinamen hinzu.Adds a group of file names to the collection of file names on which the current response is dependent.

Überlädt

AddFileDependencies(ArrayList) AddFileDependencies(ArrayList) AddFileDependencies(ArrayList) AddFileDependencies(ArrayList)

Fügt der Auflistung der Dateinamen, von denen die aktuelle Antwort abhängt, eine Gruppe von Dateinamen hinzu.Adds a group of file names to the collection of file names on which the current response is dependent.

AddFileDependencies(String[]) AddFileDependencies(String[]) AddFileDependencies(String[]) AddFileDependencies(String[])

Fügt einer Auflistung von Dateinamen, von denen die aktuelle Antwort abhängt, ein Array von Dateinamen hinzu.Adds an array of file names to the collection of file names on which the current response is dependent.

AddFileDependencies(ArrayList) AddFileDependencies(ArrayList) AddFileDependencies(ArrayList) AddFileDependencies(ArrayList)

Fügt der Auflistung der Dateinamen, von denen die aktuelle Antwort abhängt, eine Gruppe von Dateinamen hinzu.Adds a group of file names to the collection of file names on which the current response is dependent.

public:
 void AddFileDependencies(System::Collections::ArrayList ^ filenames);
public void AddFileDependencies (System.Collections.ArrayList filenames);
member this.AddFileDependencies : System.Collections.ArrayList -> unit
Public Sub AddFileDependencies (filenames As ArrayList)

Parameter

filenames
ArrayList ArrayList ArrayList ArrayList

Die hinzuzufügende Dateiauflistung.The collection of files to add.

Beispiele

Im folgenden Beispiel wird eine ASP.NET-Seite dargestellt, die im Cache ausgegeben wird.The following example is an ASP.NET page that is output cached. Der Code für die Seite erstellt eine ArrayList von Dateipfaden und ArrayList übergibt dann als Parameter in einem Aufrufen der AddFileDependencies -Methode.The code for the page creates an ArrayList of file paths, and then passes the ArrayList as the parameter in a call to the AddFileDependencies method. Dadurch wird die Ausgabe zwischengespeicherten Antworten ungültig, wenn eine der in den ArrayList angegebenen Dateien geändert wird.This makes the output cached response invalid if any of the files specified in the ArrayList changes.

<%@ Page Language="c#" %>
<%@ outputcache duration="30" varybyparam="none" %>
<%@ Import Namespace="Samples.AspNet.CS" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">

    private void Page_Load(object sender, System.EventArgs e) 
    {
        
        // Create variables and assign file paths to them.
        string file1 = Server.MapPath("authors.xml");
        string file2 = Server.MapPath("books.xml");

        // Create an array list to contain the file paths.
        ArrayList fileList = new ArrayList();
        fileList.Add(file1);
    fileList.Add(file2);
            
        // Make the page dependent upon the arrayList.
        Response.AddFileDependencies(fileList);

        // Populate the DataGrids.
        dgAuthors.DataSource = DataHelper.GetAuthorData();
        dgAuthors.DataBind();

        dgBooks.DataSource = DataHelper.GetBookData();
        dgBooks.DataBind();

        lblOutputCacheMsg.Text = DateTime.Now.ToString();

    }

</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
  <head>
    <title>PageDataDisplay</title>
  </head>
  <body>  
    <form id="Form1" method="post" runat="server">
      <table>
        <tr>
          <th style="WIDTH: 118px">
            Authors
          </th>
          <td>
            <asp:DataGrid id="dgAuthors" runat="server"></asp:DataGrid>
          </td>
        </tr>
        <tr>
          <th style="WIDTH: 118px">
            Books
          </th>
          <td>
            <asp:DataGrid id="dgBooks" runat="server"></asp:DataGrid>
          </td>
        </tr>
        <tr>
          <td style="WIDTH: 118px">
            The page was generated at:
          </td>
          <td>
            <asp:Label id="lblOutputCacheMsg" runat="server"></asp:Label>
          </td>
        </tr>
      </table>
    </form>
  </body>
</html>
<%@ Page Language="vb" %>
<%@ outputcache duration="30" varybyparam="none" %>
<%@ Import Namespace="Samples.AspNet.VB" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">

    Private Sub Page_Load(sender As Object, e As System.EventArgs)
    
       ' Create variable and assign file paths to them.
       Dim file1 As String = Server.MapPath("authors.xml")
       Dim file2 As String = Server.MapPath("books.xml")
    
       ' Create an array list to contain the file paths.
       Dim fileList As New ArrayList()
       fileList.Add(file1)
       fileList.Add(file2)
    
       ' Use the AddFileDependencies method to
       ' invalidate the output cached page if 
       ' one of the files changes.
       Response.AddFileDependencies(fileList)
    
       ' Populate the DataGrids.
       dgAuthors.DataSource = DataHelper.GetAuthorData()
       dgAuthors.DataBind()
    
       dgBooks.DataSource = DataHelper.GetBookData()
       dgBooks.DataBind()
    
       lblOutputCacheMsg.Text = DateTime.Now.ToString()
    End Sub

</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
    <title>PageDataDisplay</title>
</head>
<body>
    <form id="Form1" method="post" runat="server">
        <table>
            <tbody>
                <tr>
                    <th style="WIDTH: 118px">
                        Authors</th>
                    <td>
                        <asp:DataGrid id="dgAuthors" runat="server"></asp:DataGrid>
                    </td>
                </tr>
                <tr>
                    <th style="WIDTH: 118px">
                        Books</th>
                    <td>
                        <asp:DataGrid id="dgBooks" runat="server"></asp:DataGrid>
                    </td>
                </tr>
                <tr>
                    <td style="WIDTH: 118px">
                        The page was generated at:</td>
                    <td>
                        <asp:Label id="lblOutputCacheMsg" runat="server"></asp:Label>
                    </td>
                </tr>
            </tbody>
        </table>
    </form>
</body>
</html>
Siehe auch

AddFileDependencies(String[]) AddFileDependencies(String[]) AddFileDependencies(String[]) AddFileDependencies(String[])

Fügt einer Auflistung von Dateinamen, von denen die aktuelle Antwort abhängt, ein Array von Dateinamen hinzu.Adds an array of file names to the collection of file names on which the current response is dependent.

public:
 void AddFileDependencies(cli::array <System::String ^> ^ filenames);
public void AddFileDependencies (string[] filenames);
member this.AddFileDependencies : string[] -> unit
Public Sub AddFileDependencies (filenames As String())

Parameter

filenames
String[]

Ein hinzuzufügendes Array von Dateien.An array of files to add.

Beispiele

Im folgenden Beispiel wird ein Array von Dateinamen zur Liste AddFileDependencies der Datei Abhängigkeiten hinzugefügt.The following example adds an array of file names to the AddFileDependencies file dependency list. Wenn sich die Dateien ändern, wird die zwischengespeicherte Antwort für ungültig erklärt.If the files changes, the cached response is invalidated.

<%@ Page Language="C#" %>
<%@ Import namespace="System.IO" %>

<script runat="server">
    private void Page_Load()
    {
        String[] FileNames = new String[3];
        FileNames[0] = "Test.txt";
        FileNames[1] = "Test2.txt";
        FileNames[2] = "Test3.txt";
        Response.AddFileDependencies(FileNames);
        Response.Write("File Dependencies sucessfully added!");
    }
          
</script>

<%@ Page Language="VB" %>
<%@ Import namespace="System.IO" %>

<script runat="server">
  
    Sub Page_Load()
        Dim FileNames(2) As String
        FileNames(0) = "Test.txt"
        FileNames(1) = "Test2.txt"
        FileNames(2) = "Test3.txt"
        Response.AddFileDependencies(FileNames)
        Response.Write("File Dependencies sucessfully added!")
    End Sub
          
</script>

Siehe auch

Gilt für: