Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > How to delete temporary files when the user leaves the web page?

Reply
Thread Tools

How to delete temporary files when the user leaves the web page?

 
 
Jorge_Beteta
Guest
Posts: n/a
 
      01-06-2004
Hi experts!

This is a difficult question.

How to delete temporary files when the user leaves the web page? Is it
possible to do it with .NET? I'm starting to think it is not.

I have WebPage1.aspx. It will make some temporay files (*.gif or
*.jpg). What I need is when the user leaves WebPage1.aspx, temporary
files have to be deleted.

I try Javascript, using window.unOnload event. unOnload event will
call a Logout.aspx that will delete the temporary files using:
File.Delete("c:/Inetpub/wwwroot/temp/.gif").

'On WebPage1.aspx
<Script language="javascript">
function endSession()
{
window.open( "http://ServerName/Logout.aspx");
}
</Script>
<body onUnload="endSession()">

'On Logout.aspx
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
File.Delete("c:\Inetpub\wwwroot\temp\*.tmp")
End Sub

However, on every SUBMIT of WebPage1.aspx, it will raise
window.onUnload, which means
File.Delete("c:/Inetpub/wwwroot/temp/*.gif") will be executed on every
SUBMIT as well. But I just need it be executed when the user leaves
the page.

As you can notice, I just want to delete temporary files on a
directory when the user leaves the web page. Is it so difficult with
..NET?

Thanks a lot!
 
Reply With Quote
 
 
 
 
Mark Fitzpatrick
Guest
Posts: n/a
 
      01-06-2004
ASP.Net itself won't really know when a user leaves a page because, as far
as it's concerned, once the client has finished downloading the page they're
not connected to the server anymore. You could try making use of something
like the Session_End event that could do some cleanup. That would guarantee
that 20 minutes (or however much you set the sessions timeout to be) after
the last page that a user visits the files will be deleted. I'm not sure if
this approach will definitely work since not all objects are available in
the Session_End event, but it would provide you with an easy mechanism.

Hope this helps,
Mark Fitzpatrick
Microsoft MVP - FrontPage

"Jorge_Beteta" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) om...
> Hi experts!
>
> This is a difficult question.
>
> How to delete temporary files when the user leaves the web page? Is it
> possible to do it with .NET? I'm starting to think it is not.
>
> I have WebPage1.aspx. It will make some temporay files (*.gif or
> *.jpg). What I need is when the user leaves WebPage1.aspx, temporary
> files have to be deleted.
>
> I try Javascript, using window.unOnload event. unOnload event will
> call a Logout.aspx that will delete the temporary files using:
> File.Delete("c:/Inetpub/wwwroot/temp/.gif").
>
> 'On WebPage1.aspx
> <Script language="javascript">
> function endSession()
> {
> window.open( "http://ServerName/Logout.aspx");
> }
> </Script>
> <body onUnload="endSession()">
>
> 'On Logout.aspx
> Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
> System.EventArgs) Handles MyBase.Load
> File.Delete("c:\Inetpub\wwwroot\temp\*.tmp")
> End Sub
>
> However, on every SUBMIT of WebPage1.aspx, it will raise
> window.onUnload, which means
> File.Delete("c:/Inetpub/wwwroot/temp/*.gif") will be executed on every
> SUBMIT as well. But I just need it be executed when the user leaves
> the page.
>
> As you can notice, I just want to delete temporary files on a
> directory when the user leaves the web page. Is it so difficult with
> .NET?
>
> Thanks a lot!



 
Reply With Quote
 
 
 
 
Dan Brussee
Guest
Posts: n/a
 
      01-07-2004
Two suggestions.

1. Instead of creating temp graphic or data files, stream them to the
browser. Many examples on how to do this abound.

2. If you absolutely have to handle temp files, the generation code
should be able to clean up itself. The Page object will raise an
Unload event when it is finished. From a handler of that event, you
should be able to clean up. Of course this will mean you cannot cache
anything on that needs cleanup, but I guessing this is not a problem
since if the page is refreshed, the graphics, etc might need to be
regenerated. No?


On 6 Jan 2004 13:51:31 -0800, http://www.velocityreviews.com/forums/(E-Mail Removed) (Jorge_Beteta) wrote:

>Hi experts!
>
>This is a difficult question.
>
>How to delete temporary files when the user leaves the web page? Is it
>possible to do it with .NET? I'm starting to think it is not.
>
>I have WebPage1.aspx. It will make some temporay files (*.gif or
>*.jpg). What I need is when the user leaves WebPage1.aspx, temporary
>files have to be deleted.
>
>I try Javascript, using window.unOnload event. unOnload event will
>call a Logout.aspx that will delete the temporary files using:
>File.Delete("c:/Inetpub/wwwroot/temp/.gif").
>
>'On WebPage1.aspx
><Script language="javascript">
>function endSession()
>{
> window.open( "http://ServerName/Logout.aspx");
>}
></Script>
> <body onUnload="endSession()">
>
>'On Logout.aspx
>Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
>System.EventArgs) Handles MyBase.Load
> File.Delete("c:\Inetpub\wwwroot\temp\*.tmp")
>End Sub
>
>However, on every SUBMIT of WebPage1.aspx, it will raise
>window.onUnload, which means
>File.Delete("c:/Inetpub/wwwroot/temp/*.gif") will be executed on every
>SUBMIT as well. But I just need it be executed when the user leaves
>the page.
>
>As you can notice, I just want to delete temporary files on a
>directory when the user leaves the web page. Is it so difficult with
>.NET?
>
>Thanks a lot!


 
Reply With Quote
 
Jorge_Beteta
Guest
Posts: n/a
 
      01-11-2004
Thanks for your suggestions, Dan.

About using Page.Unload, I have to say that Page.Unload fires EVERY
SUBMIT, not only when the user close the page or leaves the page.

I use WebControls.Image to show gif files on the browser. In order to
achieve that I use Filestream:

strImgFilePath = "c:\Inetpub\wwwroot\temporal\"
strImgFileName = "random_number.gif"
'oPhoto As Byte(), is data retrieved from field/table
Dim oFileStream As FileStream = File.Create(strImgFilePath &
strImgFileName, oPhoto.Length)
oFileStream.Write(oPhoto, 0, oPhoto.Length)
imgControl.ImageUrl = "temporal\" & strImgFileName
oFileStream.Close()

As you see, I have to create the gif file in order to FileStream it.
Is it a way to use FileStream wihtout creating the gif file on a
carpet?

Thanks,
Jorge

Dan Brussee <(E-Mail Removed)> wrote in message news:<(E-Mail Removed)>. ..
> Two suggestions.
>
> 1. Instead of creating temp graphic or data files, stream them to the
> browser. Many examples on how to do this abound.
>
> 2. If you absolutely have to handle temp files, the generation code
> should be able to clean up itself. The Page object will raise an
> Unload event when it is finished. From a handler of that event, you
> should be able to clean up. Of course this will mean you cannot cache
> anything on that needs cleanup, but I guessing this is not a problem
> since if the page is refreshed, the graphics, etc might need to be
> regenerated. No?
>
>
> On 6 Jan 2004 13:51:31 -0800, (E-Mail Removed) (Jorge_Beteta) wrote:
>
> >Hi experts!
> >
> >This is a difficult question.
> >
> >How to delete temporary files when the user leaves the web page? Is it
> >possible to do it with .NET? I'm starting to think it is not.
> >
> >I have WebPage1.aspx. It will make some temporay files (*.gif or
> >*.jpg). What I need is when the user leaves WebPage1.aspx, temporary
> >files have to be deleted.
> >
> >I try Javascript, using window.unOnload event. unOnload event will
> >call a Logout.aspx that will delete the temporary files using:
> >File.Delete("c:/Inetpub/wwwroot/temp/.gif").
> >
> >'On WebPage1.aspx
> ><Script language="javascript">
> >function endSession()
> >{
> > window.open( "http://ServerName/Logout.aspx");
> >}
> ></Script>
> > <body onUnload="endSession()">
> >
> >'On Logout.aspx
> >Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
> >System.EventArgs) Handles MyBase.Load
> > File.Delete("c:\Inetpub\wwwroot\temp\*.tmp")
> >End Sub
> >
> >However, on every SUBMIT of WebPage1.aspx, it will raise
> >window.onUnload, which means
> >File.Delete("c:/Inetpub/wwwroot/temp/*.gif") will be executed on every
> >SUBMIT as well. But I just need it be executed when the user leaves
> >the page.
> >
> >As you can notice, I just want to delete temporary files on a
> >directory when the user leaves the web page. Is it so difficult with
> >.NET?
> >
> >Thanks a lot!

 
Reply With Quote
 
Shiv Kumar
Guest
Posts: n/a
 
      01-12-2004
Your ImageUrl property should point a another .aspx page (sending it any
addtional parameters if required) where in all you do is extract the data
required from your database (using the parameters sent) and stream the data
straight out to the browser using the Response.OutputStream

--
Shiv R. Kumar
http://www.matlus.com


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Can I safely delete Temporary ASP.NET Files? =?Utf-8?B?TmVvIFRoZSBPbmU=?= ASP .Net 7 04-03-2010 08:29 AM
Delete/Remove Temporary Internet files Manish ASP .Net 4 06-19-2008 06:53 AM
anonymous array of strings // ("taking address of temporary"- how long is temporary valid?) anon.asdf@gmail.com C++ 7 02-12-2008 10:58 AM
Delete session cookie when user leaves my domain? Mike Dee Javascript 0 03-02-2006 05:43 AM
Can't delete Temporary Internet Files and folders - XP Pro Rusty Knutts Computer Support 8 12-02-2003 03:37 PM



Advertisments