Avoid application reset when deleting a folder - asp.net

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.

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

ASP.NET: Writing web-accessible temp files without application restart

My ASP.Net application used to restart unpredictably during requests, ruining my state, session data etc. I determined that the problem was caused by a control that writes and deletes some files in Temp folder that it creates near bin folder, so the web directory looks like this:
bin
Temp
....
Default.aspx
web.config
ASP.Net apparently reacts to changes inside Temp folder the same way it reacts to changes inside bin or in web.config - it restarts the application.
I could partially solve the problem by moving the Temp outside the site directory. That way the application doesn't get restarted every time something temporary is written\deleted, so this part works well. The problem is that some of the files inside Temp directory should be web-accessible - like images generated on the fly and such.
So my question is actually threefold:
Should ASP.Net application get restarted even if the changes are made not in the bin directory, but in another directory at the same level? Or is there something wrong with my configuration?
Where and how do I create a temporary folder so it's web-accessible but it doesn't cause application restart?
How do I turn off restart on directory change from code or web.config (both in IIS and ASP.Net development server)?
Based on my understanding here is the answer to your questions:
ASP.NET restarts the application when too many files are changed in one of the content directories. For more info abt when app restart happens read: http://programming360.blogspot.in/2009/04/what-causes-application-restart.html
You can create the temporary folder anywhere in the same machine or on a different machine(file-share) so long as the IIS-User has access to the folder it should work normally. The only thing that you need to consider is the latency when the folder is on a different computer.
I dont believe you can control application restart and this is completely controlled by IIS. Might want to read up on this SO questions: ASP.NET restarts when a folder is created, renamed or deleted

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.

asp.net: updated pages compilation

I need to ensure that when some individual pages are updated/modified, the time required to load the other pages to the Web site remains unaffected.
A. Create the application as a Web site project.
Copy the entire application to the deployment server.
Copy only the updated files to the deployment server when a page is updated.
B. Create the application as a Web site project.
Pre-compile the application by using the update able option.
Copy only the updated files to the deployment server when a page is updated.
is Pre-compile option available for web site or its available for web app?
I can simplify this question by some ifs that contains your answer.
If you update just the ASPX files and rarely you change the code files : then
Use Website and publish it using
Allow this precompiled site to be updatable
Using this option you can change ASPX files
Use fixed naming and single page assemblies
Using this option you can change code files, and replace them with their friendly name
Update required published dlls and ASPX files when ever you need.
Note: any changes to bin folder contents may cause application restart and that means all sessions will be lost, so in this case you must consider using other session state modes like SQLServer and StateServer and once you do you need to annotate all your session classes with Serializable attribute
If you will update just the ASPX files : then
Use Website and publish it using
Allow this precompiled site to be updatable
Using this option you can change ASPX files
Else if you just need to update the ASPX HTML content : then
You might reconsider your application scenario
because you need to use data-base to rectify the update problem as any body else do
And finally if you will update web-site code-files very rarely or your changes are at application level rather than page level : then
Use web-application build or publish it if you like.
Using this option you still have the ability to change the ASPX files

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

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

Resources