session expired problem after deleting a folder and its sub folder programatically in asp.net RRS feed

  • Question

  • User602630008 posted

    hi .
    i was deleting a folder after hosting. in the same time i was maintaining session value.
    after deleting the folder then the session value become null.

    how to tackle this issue.
    my code is:
    string strFile = AppDomain.CurrentDomain.BaseDirectory + "sample"; 
    ClearFolder(strFile );
    private void ClearFolder(string FolderName)
    System.IO.DirectoryInfo dir = new System.IO.DirectoryInfo(FolderName);

    foreach (System.IO.FileInfo fi in dir.GetFiles())
    fi.IsReadOnly = false;

    foreach (System.IO.DirectoryInfo di in dir.GetDirectories())

    need ur suggestions with examples



    Tuesday, November 22, 2011 5:58 AM


All replies

  • User1643008609 posted

    Hi Friend,

    It is the default nature if you are deleting a subdirectory within your application, your app domain will restart. This removes all session data. To alleviate this issue, only add/remove directories outside your application home directory.

    So keep the folder where you want delete operation to be performed out side application folder.


    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, November 22, 2011 6:39 AM
  • User-110526006 posted


    if (Directory.Exists(folderPath))
    Directory.Delete(folderPath, true);


    Or Else Use This ....

    System.IO.DirectoryInfo d = new System.IO.DirectoryInfo(folderPath);
    if (d.Exists)

    Tuesday, November 22, 2011 7:45 AM
  • Wednesday, November 23, 2011 2:07 AM
  • User-1230741328 posted


    set this tag 

    <sessionState mode="StateServer" stateConnectionString="tcpip=" cookieless="false" timeout="1000"/>

    i hope it will help you a lot...

    Wednesday, November 23, 2011 3:09 AM