views:

46

answers:

2

Hi,
I have a asp.net/c# web app. When do user leave a certain page, I would like to delete 1 particular temp file on the client machine, in the temp file folder. Can I do this at all? Can I do this server side or client side?

Thanks.

+1  A: 

For security reasons, this is completely impossible.
(Unless you're asking to delete your own cookie)

If you don't want the browser to cache your files, you can use the HTTP caching headers.

SLaks
Why was this downvoted? Does someone think that it is possible?
SLaks
@SLaks, anything's possible. Difficult to do, a bad idea to do, but possible nontheless...
Rob
+2  A: 

You can't delete a file from the end users machine - without using something like an ActiveX. That would tie your users to Internet Explorer though.

A better solution might be to set the applicable caching directives so that the browser doesn't store the file in its cache, that way it won't actually be written to disk (I'm assuming here that the file is one that is being pulled down by the browser as part of viewing/loading the page).

For example:

    Response.Cache.SetCacheability(HttpCacheability.NoCache);


    Response.Cache.SetExpires(DateTime.Now.Subtract(new TimeSpan(1, 0, 0, 0)));


    Response.Cache.SetNoStore();

If you really wanted to do this, and it wasn't as simple as preventing a file from being cached then as I said, using an ActiveX would be pretty much the only option. If you were going to develop an ActiveX control to do this, I'd strongly recommend you review MSDNs documentation on Per-Site ActiveX Controls. Deploying an ActiveX control, even within an intranet, that allowed files to be deleted from the end users PC from any domain could only be considered reckless at best, negligent at worst.

Rob
Yes, it's a file being pulle by the browser. Could you show the ActiveX method too? Over here, you are only supposed to use IE so... Thanks.
Frank
@Frank, see the comment I've added about per-site AX controls =)
Rob
Unfortunately, all the files are still there... I guess this should be called in the Page_Load() ?
Frank
@Frank - the commands above will only apply to the ".aspx/.axd/.ashx" that they're executing within, and yes - it should be in Page_Load(). If you're trying to use them to cause a file to be cleared out that's not processed by asp.net (eg. a pdf/gif/png) then it won't work. You'd need to pass the content of the file through asp.net to achieve that (or look at configuring caching settings at the server level).
Rob
Well... it was actually an xml file, but thanks, you helped me find the right solution, I've set a no-cache on IME type via ISS and no xml file are kept on the client machine.
Frank