Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Deleting Directory at runtime

Tags:

c#

.net

asp.net

I just want to delete the Directory which is in the project folder.

That folder having all web sharing authority and permission.

The problem is arising when i am deleting the folder.

Folder is deleted from the serverpath(Virtual Directory).

But my problem is that when i complete my task and click on any control it will redirect me to the Login page with the return url as there is a secure authentication on the root directory is available

like image 506
Vir Avatar asked May 14 '11 08:05

Vir


People also ask

How do you force delete a file while running?

In the command window, type the DEL /F file name command and press Enter to force delete the file that is in use. Note: In the above command, the file name must be replaced by the name of the file along with its extension that you want to delete. For example del /f TestFile.


2 Answers

Application domain recycled when Sub-Directories are deleted, that's why your session will lost and you are redirected to the login page.

For more details, check this article from MSDN Blog and read Why does an application domain recycle? from here ASP.NET Case Study: Lost session variables and appdomain recycles

and also check this one Deleting ASP.NET 2.0 Application Sub-Directories Shuts Down the AppDomain

like image 67
Muhammad Akhtar Avatar answered Sep 23 '22 02:09

Muhammad Akhtar


As noted in another answer, this is because the web app is restarted whenever you delete a folder inside the web app's directory structure (i.e. below the web app's root directory).

The only solution I found for this problem is to move the data directories (which you create/delete/modify) outside the web app's root directory / virtual directory.

Then we create a link (junction) in the file system so that the directory appears to be inside the virtual directory. This prevents ASP.NET from monitoring the data directory for delete operations.

Example:

  • Our web site (virtual directory) is located at C:\projectX\website
  • the data directory (where we create/delete files and folders) is located at C:\projectX\data
  • then we create a link which makes the data folder available as C:\projectX\website\data

The link is created using the program Linkd.exe (available in the windows resource kit), with the following command:

linkd c:\projectX\website\data c:\projectX\data

Now C:\projectX\website\data is a link/junction which points to the real data directory. Inside your web app, you can continue working as if the data directory were a physical directory below the web app's root directory.

E.g. in your web site you can access the data folder using this code:

Server.MapPath("~/data")

And you can also used the windows file explorer and browse to C:\projectX\website\data. It appears just like a real directory.

As you can see, you can continue to use the linked data folder as if it were a normal folder inside the web app's directory. The only difference is that ASP.NET will not track the directory for delete operations and will therefore not restart the application. This means, you can now create/delete/modify folders and files inside the ~/data directory as you wish, without having the web app restarted.

like image 27
M4N Avatar answered Sep 20 '22 02:09

M4N