Why does my asp.net application recycle when I delete a folder? - asp.net

I have a Silverlight application using a WCF service hosted in IIS. I make use of some aspects of ASP.NET.
I have the following folder structure for my application:
inetput
wwwroot
myapp
reports
{user-guid-folders}
report1.pdf
report2.pdf
App_Data (folder)
bin (folder)
Client_Bin (folder)
(various .aspx files, plus web.config, etc.)
The application dynamically generates reports and puts them in a folder with a GUID for the name which is unique to the user. This all works fine.
However, when the user logs out I was cleaning up and deleting the PDF files in their folder, then deleting their GUID folder.
Deleting the files works fine, but if I delete the folder, the application recycles (which then removes all other users' sessions - I get a Session_OnEnd event for every user's session, and an Application_OnEnd event. The next user request causes the whole application to restart.
So, while I can fix this by not deleting the GUID folder (which my application itself created), what is the reason for this? Is there any way I can prevent this from happening?

The following article talks about this issue...
http://blogs.msdn.com/b/toddca/archive/2005/12/01/499144.aspx

Related

Clear Temp ASP.NET files from Azure Web Site

I have a issue with a ASP.NET nopCommerece Plugin that seems to be cached on the server.
I have cleared the nopCommerce cache and restated the application but it didn't help
One of the normal steps is to clear out \Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files but since this is a Azure Web Site, I only have access via FTP and I don't have access to that directory.
How do I go about clearing the Temp Files.
when you publish the website on to azure, by right clicking and choosing publish, there should be a option under setting saying: Remove additional files at destination. Check it and publish.
I managed to do this by creating a temporary file in the bin folder of my website.
This casuses the temporary hash file to change in the temp folder and then ASP.Net rebuilds everything.
See here for more details about the hash file and its relation to rebuilding.
Remove Additional files didn't fix my problem as it only removes files in webroot not the temporary asp.net files. As far as I can see with Azure you have no access directly to the temporary asp.net files

How to constraint IIS app pool from refresh if some files change?

I have ASP.NET MVC application and it contains some folders with files which can be changed in real-time while the application runs in IIS.
When I change certain files with extensions like .resx (without code generation) and .xml (with custom content) my application pool gets refreshed and I don't want this behaviour, however if I change .cshtml then the pool doesn't refresh.
When I put mentioned "problematic" files in App_Data folder then the pool won't be refreshed, but maybe there's solution for other folders too.
For example if I have such folder structure in my application:
App_Code
App_Data
- file1.resx // when its content changes the pool DOESN'T get refreshed
- files2.xml // when its content changes the pool DOESN'T get refreshed
- files3.cshtml // when its content changes the pool DOESN'T get refreshed
CustomFolder
- App_LocalResources
-- file1.resx // when its content changes the pool gets refreshed
-- files2.xml // when its content changes the pool gets refreshed
-- files3.cshtml // when its content changes the pool DOESN'T get refreshed
How to prevent IIS application pool from refresh if some certain files or file types changed?
Thanks for any help.
I think App_Data is a special directory the is ignored for the application restart/reload, since a lot of dynamic/changing content can end up there.
From MSDN about resx files:
The .resx (XML-based resource format) files are converted in to common language runtime binary .resources files that can be embedded in a runtime binary executable or compiled into satellite assemblies.
From that, I think the application is being restarted because the resx file is being compiled at runtime.
I don't think there is a way to prevent this behavior. There are some ideas on How to prevent an ASP.NET application restarting when the web.config is modified? but I haven't tried any of these.
Found a solution.
The problem of app pool recycling when .resx files change was lying in App_LocalResources folder. I moved all the files from this folder to a new folder named Resources (works pretty much the same as App_Data since it's not system folder).
New folder structure looks as follows:
App_Code
App_Data
- ...
CustomFolder
Resources
file1.resx
files2.xml
files3.cshtml

Avoid application reset when deleting a folder

I'm having a bit of trouble with an ASP.Net MVC project.
The users can upload images, which are stored with an ID in the database, and the files are then stored in /Files/Images/ID/
Upon deleting the images again, I delete the folder /Files/Images/ID (that's the ID folder being deleted)
However when deleting a folder under the project, the application immediately resets, thereby losing all session and throwing all my users off.
Is there any way to mark a path so ASP.Net doesn't reset upon changes being made to the path ?
It's very simple. Your ASP.NET application should not be performing file write or modify operations within the paths of your ASP.NET application. Use a different path for where you store the uploads.

ASP.NET Protect files inside folder

I have a shared hosting account in which I upload my ASP.NET application. I let the user upload .doc files inside a folder, the problem is I only want logged users to be able to download those files, so I wrote a dispatcher, you give it the id and it reads the file and writes it to the browser, hiding the file location, nevertheless I want to protect the directory where all the files are, so you can only download files using the dispatcher, I tried marking it as a password protected directory, but now ASP.NET can't get access either.
You need to restrict the NTFS permissions on that folder to only allow the user your applicaiton is running as. This might be difficult in a shared host environment...
The ideal solution would be to move the folder outside of the site root but I guess as you are using shared hosting this may not be possible.
One other solution would be to move docs to the App_Data folder which is protected by .NET (see here What is the App_Data folder used for in Visual Studio?)

ASP.NET Session & Delete Folders

I have a web app where the administrator can create news, pdf documents and other stuff in his cms panel.
The problem is when the admin delete a new or something else the app deletes all the files related to that new, I mean the images, pdfs and other documents. Tha main problem is those files are stored in folders under the "news" folder and when the app deletes them the session is lost.
How can I do to have a file system without losing the session?
I'd like that file system within the app folder...
Impossible for us to store those folders outside the app and we don't want to use StateServer because of the performanne....
Any other solution?
Thanks
Your session is lost becasue IIS recompiles. The easiest solution in my opinion is to store your files outside the wwwroot.
Discussed on SO: ASP.NET restarts when a folder is created, renamed or deleted
[Update]
Example:
Let's stay your app is in c:\inetpub\wwwoot\virtualdir1
You make a work directory:
c:\inetpub\inetwork
Give the proper rights (read/write/etc) to the Asp.net user of your app pool and it should all work like a charm.
More info on setting the rights: What are all the user accounts for IIS/ASP.NET and how do they differ?
Store the path to the workdirectory in your web.config (you no not want to hardcode it)
Having those files within the app folder is a poor desgin. The session is probably lost as you are causing IIS to recycle due to the file system changes. It is much safer to not have your web application able to write to its own folder, doing so is a security risk.
Separate your document folder and web site folder. And give right permission your document folder.

Resources