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