Session_End?

B

Bonj

Hi
I have an ASP.NET application which implements a server-side charting
solution, for this it needs to generate .gif files which are then sent to
the browser via a literal which has its text set to "<img src=\" +
graphfilename + \"/>. This is all working beautifully, however all these
..gif files are going to build up on the server and are going to need
deleting. I tried putting some code in the Session_End function in
global.asax, but Session_End *NEVER* fires. (I proved this to be the case
because I put some code to write to a log file on Session_Start,
Session_End, Application_Start and Application_End. After a couple of days,
the *_End ones never logged once, but there were about 5 Application_Starts
(which I presume represent the first time it started after a rebuild?) and a
load of Session_Starts). This is the case no matter whether a debug build or
release build is done.

Short of creating a bot that will be scheduled to run every 24 hours to
delete all old files, how can I delete all the files as soon as possible,
but after they are needed?

I tried putting Response.Flush() and then deleting the file after that, but
the browser doesn't then get the image. I'm tempted to try creating a new
thread that waits for a few seconds, deletes the file, then dies. But this
sounds messy as I don't know how good an idea it is to create an extra
thread from a code-behind in an IIS application, what with IIS obviously
being extremely multithreaded itself intrinsically.
Given that Session_End never fires, what would be the best way to delete
files as and when they are used, but making sure that the browser has had
chance to pick them up?
Or would the bot be a better solution ? I'd certainly be happy with that,
although if there is cleaner solution I'd like to know what it is in order
to implement that instead.#
 
R

Roger Twomey

I have used Session_End before and it worked. This is curious.

Can you post a sample of how you were doing your testing?

Is it possible the code caused an error which would not be logged, then
abandoned the session?
 
G

Guest

Can you post a sample of how you were doing your testing

//This is in global.asax
protected void Session_End(Object sender, EventArgs e

LogToText("Session ended")


protected void LogToText(string message

System.IO.StreamWriter sw = new StreamWriter(Server.MapPath(@"tempcharts\logfile.txt"), true)
message += " " + DateTime.Now.ToString()
if((User != null) && (User.Identity != null)) message += " (user = " + User.Identity.Name + ")"
sw.WriteLine(message)
sw.Close()


Is it possible the code caused an error which would not be logged, the
abandoned the session

No, it wasn't erroring. I put exactly the same function call in Session_Start and Application_Start only passing a different string, and that worked fine

I think I'll go for a daily bot. Never mind
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Session_End 2
Session_End 3
Session_Start/Session_End 3
Global.asax: Session_End() Behavior 12
Session_End 14
(discord.py) 'async_generator' has no attribute 'flatten' 1
Testing if session_end fires 0
Session_End 4

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,073
Latest member
DarinCeden

Latest Threads

Top