Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to use and scope of global.asax (for file cleanup after application ends)
    text
    copied!<p>On the subject of dynamically storing temporary images and handling their cleanup on a web server's file system: (using C# in .NET 3.5).</p> <p>It was suggested that I use a <code>global.asax</code> file to handle this.</p> <p>I just can't figure out how this thing works.</p> <p>I have two separate applications...</p> <p>I have figured out that the global.asax is supposed to be in the root directory of the website.</p> <p>Questions:</p> <p>1) How to I get the <code>global.asax</code> to fire for only these two specific applications.</p> <p>2) both applications need to create a list of strings (the file locations) then delete them on the application termination. Do I instantiate this array in the app, or in the <code>global.asax</code>?</p> <p>My code will look like this:</p> <pre><code>List&lt;string&gt; fileLocations = new List&lt;string&gt;(); //I don't know where to put this. //The next line of code will be in both applications (this could //be called many times in one application session. The names of //the files are generated from the clock (milliseconds and //seconds combined, I might change this to use the actual //random class combined with sessionID) fileLocations.Add(file); void Application_End(object sender, EventArgs e) { // Code that runs on application shutdown foreach(string file in fileLocations) { if(File.Exists(file)) File.Delete(file); } } </code></pre> <p>I am confused about how the global.asax actually works. Is it used like an interface?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload