ASP.Net compiliation - asp.net

I have a question about asp.net compiling. I know the different ways you can compile but my question is with the default method.
Microsoft says that pages and code are compiled on their first use and then cached. My question is, when does that cache clear...
when the app pool recycles? Or, does it cache it until it's changed even through server reboots. Basically, if it compiles once and then caches it until it's changed I'm ok with it... if it recompiles with every reboot or app pool recycle I'm going to go the route of pre-compiling.

The cache is cleared upon app pool shutdown, at each app pool startup it is re-compiled and cached.

Whenever you change something to the source files it will recompile.
On startup (after shutdown) it will recompile too.
Changing something to the web.config reboots your web

So the files are created in a temp folder but do not get cleared on shutdown. They will only be recompiled if something changes. So if you restart IIS or reboot the machine, they will not recompile. Just reload them from the temp folder.
Changes to any of the files of the project, or any files the project is dependant on will cause a recompile.

Related

application_start doesn't hit after iisreset or web.config changes

The situation is weird. We've developed a deployment system for our internal use. The system downloads precompiled binaries and copy to application directory using robocopy, excluding unchanged files.
The problem is, after this operation, the application doesn't hit application_start. Even we restart application domain. (I even restarted the IIS itself but no luck) I even change web.config manually after auto-deployment, again no luck. I run iisreset, the same, did not hit application_start. But the application is running! we use a state server, and we continue to use application like nothing happend (except application variables, they all disappear)
In application_start, we initialize some Application variables by adding like following:
logger.info("bla bla");
Application.Add("KEY",somevaluefromdb);
We do not see any log messages too.
But when i deploy same binaries manually (by copying and pasting.), the application_start hits, we see log message, and the variables are initialized.
Did anyone encounter such situation?
If PrecompiledApp.config file does not exist at publishing app root folder, the events would not execute.
I spend hours for this meaningless error :(
Related answer: Global.asax not firing for Release build

changes to web.config or app_code folder doesn't recompile (webfarm)

i have few virtual PCs in a webfarm setup. each of the PCs are setup to run webserver which points to the same network share folder.
problem I'm facing is, whenever I do changes to global.asax, web.config, or in app_code folder, it doesn't recompile. restarting IIS, PC, or recycling application pool has no effect.
I had to delete the files in "windows\microsoft.net\framework64\v4.0.30319\temporary asp.net files\root\", only then it will recompile with the new file changes. Shouldn't it recompile whenever there are changes to those files/folder?
what can I do to force it to recompile everytime there are changes to those?
You should really not be relying on the fly compilation, I would recommend publishing your website as a precompile to the network share. See http://msdn.microsoft.com/en-us/library/vstudio/bb398860(v=vs.100).aspx. Also app_code has some severe limitations, you should consider putting those classes in a separate assembly.

ApplicationShutdownReason.BuildManagerChange and ApplicationPool restart in IISExpress

We have a problem. We are using IISExpress 8.0 for Asp.net WebForm application(.net 4.0).
Comupter is running under Windows 7 x64.
Sometimes without any reason ApplicationPool restarts. I know that it will restart after 15 aspx\ascx file changes. But in that case it restarts without any changes.
On ApplicationEnd we found a reason of this restart. It's ApplicationShutdownReason.BuildManagerChange.
Search in the Internet won't give anything usefull details. Mostly all recomends to use IIS instead of IISExpress.
Do you know what could be a reason for it?
UPDATE:
Digging deeper into .Net 4 source code give two reasons of this shutdown.
One of them is triggered when someone changed hash.web file from Temporary Asp.net folder. For example - "c:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET Files\app\a83dcad1\be4aa699\hash\hash.web"
Second reason is when BuildManager built some object and cached BuildResult in HttpCache. And then if it's expired it checks that this BuildResult require ShutdownAppDomainOnChange on cache expiration. And if it's require it, then it triggers BuildManagerChange shutdown.
UPDATE2
In our case restart was caused by hash.web change. Seems IISExpress updates it without any source code change, but why?
UPDATE3
Microsoft has an issue about it - https://connect.microsoft.com/VisualStudio/feedback/details/783440/microsoft-visualstudio-web-host-exe-touches-hash-web-and-should-not-be-running
They say that they fixed it in Visual Studio 2012 Update 2.
This is not a full answer, so take whatever benefit from it you may take.
It seems like two things are happening: the hash.web change is probably because IIS uses the temporary location to store the application DLL that you build. When this file changes, IIS understands that you built a new version of the application, and need to restart it; that may explain the application pool reset.
For the cache expiration, it seems like IIS is trying to unload and reload something in a different app domain. There's no way (in .NET) to unload an assembly without unloading an app domain (I think) once it's been loaded, so this is "the usual" way to achieve this.
Maybe.

How to refresh Mono ASP.NET page without restarting the web server?

When I make changes to a file, Mono ASP.NET doesn't see my changes, I have to do this:
sudo /etc/init.d/apache2 restart
I remember when Mono ASP.NET executes ASP.NET it caches the compilation somewhere. Before, when the updated page doesn't come up, I just delete that cached compiled code. I just forgot the exact path
How to make Mono ASP.NET detects the changes I made in program, without restarting the web server?
It sounds like the FileSystemWatcher cannot see changes coming from the windows side.
After you update on the windows side, go to the linux side and do:
touch Web.Config
or any file on the directory. This should notify ASP.Net to load your new code.
This is the command to restart your App, and recompile if its needed. (with out restart the web server).
Can you test it if do the work ?
HttpRuntime.UnloadAppDomain();
The other way is to create a file app_offline.htm on root, upload your changes, and then delete it.

web.config locked by w3wp.exe

I've got a weird problem. It looks like if my IIS6 locked an application's web.config. If I try to edit it, Windows complains that the web.config is used by another process.
Using Process Explorer I can see that the file is owned by w3wp.exe. Removing the virtual directory and stopping the website wasn't useful at all.
Any idea (I cannot stop the whole server since a lot of sites are hosted in it)?
Thanks in advance
I would try stopping the application pool for the website that is accessing the web.config.
I had this problem, stopping the application pool didn't help. I then tried launching my text edited as administrator, and then that allowed me to save the file. Unfortunately I don't know if I needed to stop the application pool or not in the end...
Best bet would be to rename the web config (maintianing the lock on that file) and recreating the file. I'm not sure what would lock the file, but the app pool recycle should have freed the lock.
type iisreset in cmd will also solve this issue
If you're using an x32 based system, you could try using Unlocker to 'unlock' the file, or possibly delete web.config and then recreate it. Failing that, you could kill the w3wp.exe worker process, which should automatically restart.

Resources