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

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

Related

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

asp.net/vb.nrt select local web.config file only

I am deploying an asp.net solution written in vb.net, the solution works fine on the localhost server and on my development server. On the live server the solution keeps ignoring the local web.config file and is using one belonging to another persons project which I have no control over.
This is the list of files that are in the folder I uploaded to the live server:
imageFolder
Default.htm
FormDelete.aspx
FormDelete.aspx.vb
thankyou.htm
web.config
I want my solution to only look at the web.config located in the same folder as it, and not inherit any values from another web.config file. Can this be done?
Thank you in advanced
This happened to me some days ago; as I was the owner of them both, I deleted the app I didn't need, and restarted IIS.
Maybe there are some similarities between your app and the other one, or there is some bad redirection, I don't know. In my case, the other app just linked to a test database, that's how I knew there was an issue.

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.

Updating an existing ASPX application without success

I've a little problem, with a ASPX .NET application that I'm updating.
After having updated the DLL and the ASPX files on the production server, my application is still running not modified.
Is there a method to force IIS reloading the application without restarting the server?
Create the app_offline.htm file on the root of your www, then make your modifications, then delete it (or just rename it)
If you all ready update your dlls, create the app_offline.htm, then just make any small update to web.config (by just add an empty line) save the web.config, then delete the app_offline.htm (or just rename it)
the app_offline.htm, force your application to stop and restart and then the dot net see the changes and recompile it.
When the app_offline.htm is open, all pages show the content of this file, so you can place inside of this file any messages to your viewers.
Visual studio make the same trick when its starts with this file.

why the session in iis automatically log out?

I used iis6, and when i called a function Directory.delete(), the all the session relate this website will be logged out.
and i debugged the website, i found no exception.
any one have ideas on this ?
Thanks in advance!
I assume the directory you are trying to delete is within the website folder.
When you delete a folder inside a website, then asp.net will restart resulting in loss of session state.
To avoid this problem
1) Try to implement out-of-process session state.
OR
2) Move the folder out of web application folder.
If you create, delete or change any directory or files underneath the web application directory while the app is running, ASP.NET unloads the appdomain thinking that the code has changed and needs to be reloaded. This clears all session state, etc. You'll need to move any file/directory create/delete/change stuff to a directory outside the web application directory.

Resources