HttpResponse.AddFileDependency(String) 方法

定義

將單一檔案名稱加入目前回應所依存的檔案名稱的集合。Adds a single file name to the collection of file names on which the current response is dependent.

public:
 void AddFileDependency(System::String ^ filename);
public void AddFileDependency (string filename);
member this.AddFileDependency : string -> unit
Public Sub AddFileDependency (filename As String)

參數

filename
String

要加入的檔案名稱。The name of the file to add.

範例

下列範例示範如何將單一檔案名AddFileDependency加入檔案相依性清單中。The following example shows how to add a single file name to the AddFileDependency file dependency list. 如果檔案變更,快取的回應就會失效。If the file changes, the cached response is invalidated.

String FileName;
 FileName = "C:\\Files\\F1.txt";
 Response.AddFileDependency(FileName);
    
Dim FileName As String
 FileName = "C:\Files\F1.txt"
 Response.AddFileDependency(FileName)
    

備註

當您使用AddFileDependency方法來新增檔案相依性時,您也必須以程式設計或宣告方式指定輸出快取。When you use the AddFileDependency method to add a file dependency, you must also specify output caching programmatically or declaratively. 例如,若要以宣告方式指定輸出快取,請使用@ OutputCache指示詞。For example, to specify output caching declaratively, use the @ OutputCache directive. 如需詳細資訊,請參閱如何:具有檔案相依性的快取頁面輸出。For more information, see How to: Cache Page Output with File Dependencies.

適用於

另請參閱