Delete folder when session time-out..

Last post 12-28-2007 7:57 AM by Hardik Dave. 17 replies.

Sort Posts:

  • Delete folder when session time-out..

    08-09-2007, 7:25 AM
    • Participant
      1,333 point Participant
    • venkatzeus
    • Member since 10-27-2006, 2:27 PM
    • Posts 539

    Hi..

    I have a web application in VS2005( C#). The user can review records through the web application. Every time a record is reviewed it creates a folder in inetmgr under web application folder. So if the user reviewed thousands of records, this is going to be disastrous.

    How to do the house keeping of the records?

    In the Global.asax file, I have written as:

    void Application_Start(object sender, EventArgs e)

    {

     

    // to get the path for MP3Downloads folder

    Application["MP3DOWNLOADSFolderPath"] = Server.MapPath("~/MP3DOWNLOADS//");

    }

    void Session_End(object sender, EventArgs e)

    {

       string MP3DOWNLOADSFolderName = Application["MP3DOWNLOADSFolderPath"].ToString() + Session.SessionID.ToString();

       if (System.IO.Directory.Exists(MP3DOWNLOADSFolderName))

       {

         System.IO.Directory.Delete(MP3DOWNLOADSFolderName, true);

             if (System.IO.Directory.Exists(MP3DOWNLOADSFolderName))

               {

                    System.IO.Directory.Delete(MP3DOWNLOADSFolderName);

               }

        }

    }

     

    When I used the above code, I am facing the problem of the IIS getting re-started. Another thing is,if one of the users encounter any error, and when the user logs out, the other users are also gettng logged out..

    How to do the house keeping of the records?

    Please help.. Thanks

  • Re: Delete folder when session time-out..

    08-09-2007, 8:04 AM
    • All-Star
      21,648 point All-Star
    • gunteman
    • Member since 07-11-2007, 12:57 PM
    • Norrköping, Sweden
    • Posts 3,177

    You have to work around the appdomain restart issue (major MS screwup, if you ask me...)

    http://blogs.msdn.com/toddca/archive/2005/12/01/499144.aspx 

    -- "Mark As Answer" if my reply helped you --
  • Re: Delete folder when session time-out..

    08-09-2007, 8:21 AM
    • Contributor
      3,557 point Contributor
    • ravipahuja1
    • Member since 06-27-2007, 6:58 AM
    • Delhi NCR
    • Posts 629

    Can you use the window service. Lets mark the folder which are needs to deleted, either assigning a special name to folders or saving flag in database and let window service run at regular intervals like evey day or after every some hours.

     

  • Re: Delete folder when session time-out..

    08-09-2007, 8:21 AM
    • Participant
      1,333 point Participant
    • venkatzeus
    • Member since 10-27-2006, 2:27 PM
    • Posts 539

    Thank you for the reply.

    But, Is there any code work-arounds...

    Please help..

  • Re: Delete folder when session time-out..

    08-09-2007, 8:26 AM
    • Participant
      1,333 point Participant
    • venkatzeus
    • Member since 10-27-2006, 2:27 PM
    • Posts 539

    Hi..

    The SessionId forms the folder name.

    As the folder is created in the inetmgr, deleting the folder is making the IIS re-start..

  • Re: Delete folder when session time-out..

    08-09-2007, 8:42 AM
    • Contributor
      3,557 point Contributor
    • ravipahuja1
    • Member since 06-27-2007, 6:58 AM
    • Delhi NCR
    • Posts 629

    Look at the link is provided by

    gunteman above

  • Re: Delete folder when session time-out..

    08-09-2007, 8:55 AM
    • Participant
      1,333 point Participant
    • venkatzeus
    • Member since 10-27-2006, 2:27 PM
    • Posts 539

    Hi..

    I checked the link, But the solution provided over there is too complex and has limitations.

  • Re: Delete folder when session time-out..

    08-09-2007, 9:15 AM
    • Participant
      1,843 point Participant
    • bpw
    • Member since 09-25-2004, 5:57 AM
    • Warrington, England
    • Posts 401

    I tried the Todd Carter ‘Linkd’ solution and got it working, but it wasn’t the answer for me. I’m listing directories in a treeview and the application ‘believed’ that the deleted folder was still there and raised an exception when it thought it should come across it.

    In the end I decided on a similar approach to ravipahuja1’s suggestion. I delete the folder contents and put a marker file inside the folder. You could use anything that is unlikely to be used for a real file, e.g. xxx.xxx. When the app comes across a folder with this file it ignores it. I just need to write a routine to remove all these folders at regular intervals. I haven’t used windows services, so I’ll have to look at that.

    Bear in mind that renaming a folder will also cause an application restart.

    I agree with gunteman, this is a major headache with .NET 2.0 and I don’t think MS intend to change it.

    Paul Weston
  • Re: Delete folder when session time-out..

    08-09-2007, 9:39 AM
    Answer
    • Participant
      1,333 point Participant
    • venkatzeus
    • Member since 10-27-2006, 2:27 PM
    • Posts 539

    Hi..

    I googled and found out this: http://connect.microsoft.com/VisualStudio/feedback/Workaround.aspx?FeedbackID=240686

    Could you please help me the way you had done..

    Thanks

  • Re: Delete folder when session time-out..

    08-09-2007, 10:07 AM
    Answer
    • All-Star
      21,648 point All-Star
    • gunteman
    • Member since 07-11-2007, 12:57 PM
    • Norrköping, Sweden
    • Posts 3,177

    Just copy the code from the workaround:

     

    PropertyInfo p = typeof(System.Web.HttpRuntime).GetProperty("FileChangesMonitor", BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static);
    object o = p.GetValue(null, null);
    FieldInfo f = o.GetType().GetField("_dirMonSubdirs", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.IgnoreCase);
    object monitor = f.GetValue(o);
    MethodInfo m = monitor.GetType().GetMethod("StopMonitoring", BindingFlags.Instance | BindingFlags.NonPublic);
            m.Invoke(monitor, new object[] { }); 

      ..and add it to a good place, such as Application_Start in global.asax

    You must add "using System.Reflection" to Global.asax.cs 


    -- "Mark As Answer" if my reply helped you --
  • Re: Delete folder when session time-out..

    08-09-2007, 12:09 PM
    • Participant
      1,333 point Participant
    • venkatzeus
    • Member since 10-27-2006, 2:27 PM
    • Posts 539

    Thank you very much for the reply. I will work on the code, and provide the response..

    Thanks

  • Re: Delete folder when session time-out..

    08-13-2007, 3:29 AM
    • Participant
      1,333 point Participant
    • venkatzeus
    • Member since 10-27-2006, 2:27 PM
    • Posts 539

    Hi.. I had used the code as you had mentioned, and it is working fine. But will that lead to any other performance or memory leak issues?

    Thanks

  • Re: Delete folder when session time-out..

    08-13-2007, 5:48 AM
    • All-Star
      21,648 point All-Star
    • gunteman
    • Member since 07-11-2007, 12:57 PM
    • Norrköping, Sweden
    • Posts 3,177

    venkatzeus:

    But will that lead to any other performance or memory leak issues?

     I doubt it. It's just shutting down the file monitoring. 

    -- "Mark As Answer" if my reply helped you --
  • Re: Delete folder when session time-out..

    08-14-2007, 9:24 AM
    • Participant
      1,333 point Participant
    • venkatzeus
    • Member since 10-27-2006, 2:27 PM
    • Posts 539

    Thank you very much for the reply.

    I will let you know, if the code leads to any other Performance Issues,so that it can be helpful for all.

    Thanks

  • Re: Delete folder when session time-out..

    08-19-2007, 9:10 PM
    • Participant
      1,238 point Participant
    • pankajgohel
    • Member since 08-20-2007, 1:07 AM
    • Ahmedabad , India
    • Posts 276

    Hi I had also same problem in my application. So it is resolved by the solution given in this thread.

    So first i would like thanks to you all.

    And please let me know if is there any side effect of this.

    One again Thanks

    Regards

    Pankaj

    Thanks
    Pankaj Gohel

    Please Mark as Answer if you find the post useful.
Page 1 of 2 (18 items) 1 2 Next >