I’m trying to delete files created by current user when he/she clicks logout button
Protected Sub OnLoggingOut(ByVal sender As Object, ByVal e As EventArgs) Handles LoginStatus1.LoggingOut
Try
Dim folder As String = Server.MapPath("~/uploads/")
Dim files As String() = Directory.GetFiles(folder)
For Each f In files
Dim filename As String = Path.GetFileName(f)
If filename.Contains(HttpContext.Current.User.Identity.Name) Then
File.Delete(filename)
End If
Next
Catch ex As Exception
LogFile(ex.Message(), DateTime.Now)
End Try
End Sub
This event gets executed/called and even file.delete but files don’t get deleted.
Is there something wrong with this code or server doesn’t execute any server methods on logging out?
How can i delete files when session ends ?
It gives me error saying server methods cannot be executed
seems like a complicated way of doing things..
do they files have to be deleted right at end of user session?
why don’t you write a small program that watches that directory, and deletes any files that are longer than n period. (session length, or 24hrs or whatever).
number of utilities exist, and .net great support for it as well.. than you don’t have to worry about orphaned files because application restarted and user session events didn’t fire correctly.. also would be more secure as your asp.net application wouldnt need IIS directory write access. just small standalone windows service would handle it.