Directory.Move ---> Losing Session...

G

Guest

I have noticed that the Directory.Move removes the session as soon as the
next Response.Redirect is done. It also appears that .Net framework
constantly monitors all the directories below the root and invalidates the
inproc session. Can this be caught as an exception and ignored.

In the meantime, I have figured out a variant of Directory.Move that seems
to solve this problem.

===========================================
public static bool MoveFolder(string sourcePath, string destPath)
{
FileInfo fi;
DirectoryInfo di;
string destFileName;
String strDesSubDirectory;
try
{
if (
(!Directory.Exists(sourcePath)) ||
(Directory.Exists(destPath))
)
{
return false;
}
Directory.CreateDirectory(destPath);
// Copy the Files
foreach(string srcFileName in Directory.GetFiles(sourcePath))
{
fi = new FileInfo(srcFileName);
destFileName = destPath + @"/" + fi.Name;
File.Move(srcFileName, destFileName);
}
// Create the Directories
foreach (string strSrcSubDirectory in
Directory.GetDirectories(sourcePath))
{
di = new DirectoryInfo(strSrcSubDirectory);
strDesSubDirectory = destPath+ @"\" + di.Name;
return MoveFolder(strSrcSubDirectory, strDesSubDirectory);
}
Directory.Delete(sourcePath, true);
}
catch
{
return false;
}
return true;
}
=============================================
 
G

Guest

jojobar said:
(abridged) It also appears that .Net framework
constantly monitors all the directories below the root and invalidates the
inproc session. Can this be caught as an exception and ignored.
ASP.NET monitors its application directory and automatically recompiles
its pages if a change is detected. When this happens you'll loose
session state.

You could prevent this from happening by canceling the Session_End and
Application_End events in global.asax, but I wouldn't recommend doing
this as the side effects wouldn't be justifiable.

Anders Norås
http://dotnetjunkies.com/weblog/anoras/
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,226
Members
46,815
Latest member
treekmostly22

Latest Threads

Top