locked
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;
    fi.Delete();
    }


    foreach (System.IO.DirectoryInfo di in dir.GetDirectories())
    {
    ClearFolder(di.FullName);
    di.Delete();
    }
    }

    ----------------------------------
    need ur suggestions with examples

    regards

    gopal.s

    Tuesday, November 22, 2011 5:58 AM

Answers

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.

    http://stackoverflow.com/questions/638668/delete-directory-from-asp-net-application-returns-to-new-session

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

    Hi,

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

    ----

    Or Else Use This ....

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





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

    hii

    set this tag 

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

    i hope it will help you a lot...

    Wednesday, November 23, 2011 3:09 AM