is there a way in ASP.NET to find out, wheter a *.aspx page was changed.
I need it to refresh a cached static variable in a base-page constructor.
Thank and best regards.
Presumably you know that the ASP.NET page has changed (because you've uploaded it). Why not, at that point, recycle the app pool OR do something that will cause the app pool to recycle (such as modifying web.config)?
This question...
What causes an application pool in IIS to recycle?
... talks about what causes an app pool recycle. This MSDN article...
http://blogs.msdn.com/b/tess/archive/2006/08/02/asp-net-case-study-lost-session-variables-and-appdomain-recycles.aspx
... has an excellent write up about the subject.
When you upload the new .aspx you should get a recompilation, but you might not get an app pool recycle. The number of recompilations before a recycle is controlled by config. See Tess' article (above) for details but this snippet she gives is...
[Recycling occurs when] The number of
re-compilations (aspx, ascx or asax)
exceeds the limit specified by the
setting in machine.config or
web.config (by default this is set to
15)
Related
I am developing with VS2012 also it was same with VS2010. I working on a Web Application project. I have added a virtual application on IIS and set my project root folder as localhost/MyWebApp.
It often happens, when I do a simple page edit (on .aspx files) my site loses sessions. I am sure that no server side code is changed or no runat=server tag was affected.
How can I get rid of this?
Elaborating on David's comment:
File Change Notification
ASP.NET 2.0 depends on File Change Notifications (FCN) to see if the
application has been updated, and depending on the magnitude of change
the application pool will recycle. If you or your application are
adding and removing directories to the application folder, then you
will be restarting your application pool every time.
Altering the following files also causes an immediate restart of the
application pool:
web.config
machine.config
global.asax
Any file in the /bin directory or subfolders
Updating .aspx files, etc. causing a recompile eventually triggers a
restart of the application pool also. There is a property of the
compilation element under system.web called
numRecompilesBeforeAppRestart. The default value is 20, meaning that
after 20 recompiles the application pool will recycle.
Taken from: Losing ASP.NET Sessions - Why Application Pools recycle
Answer from Hans V:
When using the default SessionState Mode "InProc", you session will
be lost when the application pool recycles. Therer are many reasons
why this could happen, but also when you change aspx files:
ASP.NET depends on File Change Notifications (FCN) to see if the
application has been updated. Depending on the change the application
pool will recycle. If you or your application is adding and removing
directories to the application folder, you will be restarting your
application pool every time, so be careful with those temporary
files. Altering the following files will also trigger an immediate
restart of the application pool:
web.config
machine.config
global.asax
Anything in the bin directory or it's sub-directories
Updating the .aspx files, etc. causing a recompile will eventually
trigger a restart of the application pool as well. There is a
property of the compilation element under system.web that is called
numRecompilesBeforeAppRestart. The default value is 20. This means
that after 20 recompiles the application pool will recycle.
Answer reference
I'm a beginner in ASP.NET 2.0.Probably this could sound too basic and stupid issue for someone expert in the ASP.NET.But this is giving me sleepless nights.
Basically i have developed a simple multilingual website with a master page and content pages which fills inside the content place holder portions of the master page. The application works great when it is configured to run on the ASP.NET Development Server 2.0. But once i publish it to run on the IIS web server it will no longer function. :( I could see from the trace that none of the session variables i use are stored and redirected to the relevant content pages.
Although the contents are displayed, the session variable values by which i take some decisions on the redirected pages are lost and i run into exceptions.
Please guide me where am i going wrong and exact procedure for Publishing an application.
Ex: my home page has URL which runs something like
http://localhost/Onlineupdate/Home.aspx?vers=1.1&lang=fr-FR
Based on the above URL, i strip and save the vers and the lang variables in a Session variable. However these are lost when hosted on IIS.
There are a dozen or so things that could cause the session data to be lost:
IIS restarting
The app pool restarting
due to a change to the web.config
due to a change to anything in the \bin directory
memory limit reached, or a bug causing the app pool to reset.
several other possible causes
Your host is actually a web farm, and you're using in-process memory, which will cause issues when one server fails over to the other, unless you're using SQL Server session state mode.
Since we don't have enough information to answer exactly what's happening in your specific situation, I'd ask you to start by reading up, starting here: http://msdn.microsoft.com/en-us/library/ms178581.aspx
Edit: I did find this blog article, which may be helpful: http://blogs.msdn.com/b/amenon/archive/2007/08/21/troubleshooting-session-loss.aspx
The following is not necessarily part of the answer, but added to try to be helpful.
If it's feasible, from my own personal experience, we've had success in eliminating our lost session issues by using the SqlServer Session State mode. Since we implemented this, our session issues have all but disappeared.
also i found the main problem that you should initialize session before use
like:
session[“id”]=””;
and after that it well work fine
In order to prevent this to happen first in the web.config set restartOnExternalChanges to false.
Now in web.config changes must be propagated manually(this means that the dev is now responsible to build a mechanism for config change propagation).
Hint: You can use file watcher for this that will listen for the web.config (or any config you use in you web. app) for changes and wrap it as a watchable configuration so you can reload the configs when they are changed.
Hope this helps
I faced the same issue in my ASP.NET MVC website .
and i have resolve it by next steps :
open IIS Manager
go to the application pools
right click on the application pool which related to your website
click on "Advanced Settings"
set "Idle Time-out (minutes)" to be "20"
set "Maximum Worker Processes" to be "1"
Click Ok to close the window
these steps has resolved my issue.
I want to know all possibilities that IIS7 application pool automatically restart.
Because I'm facing such situation and i have no idea about what should i looking for.
There are a lot of reasons that an IIS app pool may restart. The best resource I've found was a blog post ASP.NET Case Study: Lost session variables and appdomain recycles, by Tess Ferrandez that goes into detail on how to identify the issue and fix it. She lists the following reasons that an app domain will recycle:
An application domain will unload when any one of the following occurs:
Machine.Config, Web.Config or Global.asax are modified
The bin directory or its contents is modified
The number of re-compilations (aspx, ascx or asax) exceeds the limit specified by the setting in machine.config or web.config (by default this is set to 15)
The physical path of the virtual directory is modified
The CAS policy is modified
The web service is restarted (2.0 only)
Application Sub-Directories are deleted (see Todd’s blog http://blogs.msdn.com/toddca/archive/2006/07/17/668412.aspx for more
info)
If I make a change to the vb code in a classic asp page does the change get picked up automatically or is an iisreset needed?
Thanks
Quickest answer NO you do not need to reset IIS
Once the changed file is saved, the new code will run.
There's no need to reset IIS or build the project.
The ASP Script engine does maintain a cache of "compiled" scripts (where the results of parsing and tokenizing etc are stored. So that subsquent requests for the same ASP page can be processed more quickly. However the last modified date of the ASP file forms part of the cache identity of the cached page. Hence if the page has changed since the last request the cached item is dropped and a new one built when the next request arrives so it all works seemlessly.
So as the others very quickly said, you don't need an IISReset or even an App pool recycle.
It may be worth pointing out that as of IIS6 there are very very few circumstances where you would ever need to perform an IISReset. IISReset is massively draconian and high impact. Most of the time when such a "reset" is needed a simple re-cycle of the appropriate application pool will do which has a far more gentle touch.
Even back on IIS5 a close equivalent of a app pool recycle could be achieved with by restarting the appropriate COM+ application.
On Win 2003 Server (IIS6) most of the time, save the changes to the file and it works.
I have had caching problems when the files have been saved and then copied/moved to the final location which is a virtual folder in IIS.
For example:
Say C:\inetpub\wwwroot\myfolder\ is the physical path for the URL http:Myserver/myApp/
I save my files in C:\inetpub\wwwroot\test\ and everything works fine
Move/copy the files from 'test' to 'myfolder' overwriting existing files and when I access http:Myserver/myApp/ I see my old pages, not the updates.
If I add "trace=true" into my directive on an asp.net 2.0 .aspx page, will it recycle my application pool?
I know if I enable tracing in web.config that will recycle the application pool.
The webserver is IIS 6.0.
Thanks.
I'm not 100% sure but it shouldn't. Any change to a web.config file would cause an app pool reset, but a page level change shouldn't even in the directive.
Check out the section "Why does an application domain recycle?" in this link
Technically if it's the 15th re-compile it could cause a reset... but other than that no.
I believe it will just trigger a recompile of that page. Editing of an aspx file is not a trigger for an application restart.
Why not test it out and see?
Ok - I just tried it out on a testing server - adding in the "trace=true" directive on the page level did NOT recycle the application pool.
It won't. the app pool only recycles when a dll is changed in the Bin directory or if the web.config file is changed. If you are concerned about loosing your session info as that is what the question seems to me to be more related to then you can use the asp.net session state provider and that way your app pool can recycle as many times as it likes without you loosing your session.