Name
AddFileDependency
Synopsis
Response.AddFileDependency(ByVal filename As String)
Adds a file to the list of files upon which the output cache of the current request depends. If the named by the filename argument is modified, the output cache is invalidated.
Parameters
-
filename
A String containing the path and filename to add.
Example
The example below shows how you can use the AddFileDependency method to set a file as a dependency for the output cache of the current response. If the file is modified, the output cache is invalidated.
<%@ Page Language="vb" %> <%@ OutputCache Duration="300" VaryByParam="None" %> <html> <head> <title>Adding a file dependency in ASP.NET</title> <script runat="server"> Sub Page_Load( ) Response.AddFileDependency(Server.MapPath("dep.txt")) Message.Text = DateTime.Now.ToString( ) End Sub </script> </head> <body> <asp:label id="Message" runat="server"/> </body> </html>
The dep.txt
file named in the code above should
reside in the same directory as the page. The contents of the page
can be whatever you choose. If the file content is changed, the cache
will be invalidated.
Notes
The AddFileDependency method provides the same functionality as the AddFileDependencies method, but for a single file rather than multiple files.
Get ASP.NET in a Nutshell now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.