How to constraint IIS app pool from refresh if some files change? - asp.net

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

Related

ASP.NET become very slow when add or remove dll in bin folder

I have an ASP.NET site (.NET 4.0) with ~1200 dlls files
Every time I change dll in bin folder (add, remove or replace), my site became to very slow and need to wait about 10 minutes to connect again, sometime need to reset IIS
Is there any way to settings ASP.NET or IIS just load new dll, do not reload all dll?
Thank all!
ASP.NET dynamic compilation enables you to modify your source code without having to explicitly compile your code before you deploy your Web application. If you modify a source file, ASP.NET automatically recompiles the file and updates all linked resources. By default, ASP.NET Web pages and code files are compiled dynamically when users first request a resource, such as an ASP.NET page (.aspx file), from a Web site. After pages and code files have been compiled the first time, the compiled resources are cached, so that subsequent requests to the same page are extremely efficient.
You can retrieve more information about ASP.NET dynamic compilation:
http://msdn.microsoft.com/en-us/library/ms366723(v=VS.100).aspx

Where does IIS look for files

Can anyone explain, please, exactly how .net works. I create a web site in Visual Studio and publish it to a local server to a folder at
D:\WebSites\Project1
I create a web site in IIS and provide the address of the folder containing the files for the web site. When I publish the site, using 'fixed naming and single page assemblies', all the .aspx files go in the folder on the D drive and a dll for each page goes in the bin folder inside that folder.
I would assume that when someone wants to view a page in their browser, IIS retrieves the file(s) required from the folder specified, they get processed and turned into html and sent to the browser.
Recently when someone clicked a button on a page that calls a web service - a file not found error was reported. Apparently
C:\Temp\bx5tn2js.dll
could not be found. The thing is - why did IIS decide to look in C:\Temp for a file?
And, in the error message was a load of references to xml serialization. What is being serialized?
This file looks like the compile files that asp.net generates on compile.
This folder can be setup on web.config on compilation session with the
tempDirectory="C:\Temp"
If you do not have set this option asp.net is use a default folder that is usually inside the asp.net directory, inside the windows folder. But if you have set this, and this folder did not have the correct permissions, then asp.net fails to compile the project, and you can get a message like that.

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

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

Editing resource files without recompiling ASP.NET application

I'd like to enable the resource files to be editable after deployment. I read this post which suggests that this is possible, but I can't seem to figure out what settings I need to change to enable this.
I have added the App_GlobalResources folder to my ASP.NET 3.5 "Web Application" and added a resource file to this folder. I assume that the Build Action for this file needs to be changed, but no matter what I change the Build Action to, I cannot achieve the above stated functionality.
The App_GlobalResources folder and the resource file are copied into the bin directory. Once deployed, any edits to the .resx file are not being displayed.
Any ideas?
You can achieve this, and I just did it.
Select the resource file in your project. Change the Build Action to content. Make sure that the Copy to Output Directory setting is turned OFF. When you deploy your project, the App_GlobalResources directory and your .resx file will get copied to the root of your web site. You can modify the .resx file and your live site will recognize the changes.
A Web Application project is different than a Web Site project. I doubt you can achieve what you want with a Web Application project. You might check out this post:
ASP.NET Web Site or ASP.NET Web Application?
Resources are generally meant to be static. They are items such as images, strings, and files that your program consumes and can rely on being present, (and therefore can be strongly typed in the case of strings/RESX files). The reason for using resources is simply to bundle them in with your DLL's so that distribution and referencing the resources becomes much easier.
Editable at runtime suggests you might want to use project or user Settings, or maybe a database? If you need to use RESX files you might need to write code to read/write them.

Resources