Re-publishing an ASP.NET Web Application While Site is Live - asp.net

I am trying to get a grasp on how to handle updates to a live, functioning ASP.NET (2.0 or greater) Application while there are users on the site.
For example, suppose SO is an ASP.NET Web Application project. The project code compiles down to the single .DLL in the BIN folder. Now, there are constantly users on SO, so what would happen to users' actions/sessions if you would use the Visual Studio .NET "Publish" feature (or just FTP everything again manually) while they are using the site?
Would creating an ASP.NET Web Site, instead, alleviate any problems that may or may not exist with the scenario above? I am beginning to develop a web site as a user-driven Web Application, and I want to make sure that my inexperience with this would not potentially annoy the [potentially] many users that I [want to] have 24/7.
EDIT: Sorry, I should have put this in a more exact context. Assume that this site is being hosted by a web hosting service with monthly fees. I won't be managing the server itself, just what the web host allows as a user of their services.

I create two Web sites in IIS. One is the production Web site, and the other is a static Web site with an HttpHandler that sends all requests to a single static "We're updating" HTML page served with an HTTP 503 Service Unavailable. Typically the update Web site is turned off. When it's time to update, we stop the production Web site, start the update Web site, and now we can fiddle with the production Web site all we want without worrying about DLLs being locked or worker processes needing to be spun down.
I started doing this because
App_Offline.htm really does not work well in Web Gardens, which we use.
App_Offline.htm serves its page as 404, which is bad if you're down for a meaningful period of time.
We can start the upgraded production Web site with modified settings (only listening on localhost), where we can do a last-minute acceptance/verification that everything is working before we flip the switch, turning off the update Web site and re-enabling the production Web site.
Things this does not solve include
Any maintenance that requires a restart of the server--you still have downtime where no page is served.
Any maintenance that diddles with the .NET runtime, like upgrading to the latest service pack.
Other approaches I've seen include
Having two servers. Send all load balancing requests to one server, upgrade the other one; then rinse and repeat. Most of us don't have this luxury.
Creating multiple bin directories, like bin-1.0.0.0 and bin-1.1.0.0 and telling ASP.NET which bin directory to use in the web.config file. (One advantage of this is that reverting to a previous binary is just editing a config file. A disadvantage is that it's harder to revert resources that don't end up in your binaries, like templates and images and such.) I don't remember how this actually worked--I think the application did some late assembly loading in its Global.asax based on its own web.config section (since you touched the web.config, the app had restarted, so it was okay).
If you find a better way, let me know!

Changing to the asp.net web site model won't have any effect, as the recycle will also happen, some of changes that trigger it for sure: web.config, global.asax, app_code.
After the recycle, user will still be logged in because asp.net will just validate the syntax. That is given you use a fixed machine key, otherwise it will change on each recycle. This is something you want to do anyway as other stuff can break if the key change across requests i.e. viewstate validation, embedded resources (decryption of the url fails).
If you can put the session out of process, like in sql server, you will avoid loosing the session. If you can't, your code will have to consider that. There are plenty of scenarios where you can avoid using session, and others were you can wrap it and re-retrieve the info if the session was cleaned. This should leave you with a handful specific cases that you know can give trouble to the users, so for those you do some of the suggestions others have already made.

One solution could be to deploy your application into a load balanced environment (web farm).
When deploying a new version you would use the load balancer to redirect requests to the server you are not deploying to.

App_offline.htm is great solution for this I think.
in SO we see application currently unavailable page when a deployment begins.

I am not sure how SO handles it.. But we usually put a holding page. So what ever the user has done (adding question or answering questions) does not get updated. As soon as he updates something he will see a holding page asking him to try after sometime.
And if I am the user I usually press the back button to make sure what I entered is saved in the browser history so that I can post later.
Some site use use are in clustered environment so I take one server offline and inform the load balancer that she will not be available and once I make sure that the new version is working fine I make it live.. I do the same thing for the next server.
Do we have any other option?

It is not a technical solution, but set up a scheduled maintenance window. You can annoucement in advance giving your user base fair warning that there is a possiblity that the application will not be available during that time frame.

Related

IIS is hanging when requesting a folder with anonymous authentication

I recently changed the frontend of a project, to use windows authentication.
But i still want the backend to use forms authentication, I think i read somewhere that it was not possible to use both authentication methods at the same time. But I seem to have it working, sort of.
I'm using umbraco v4.7.2 - To those that doesn't know this CMS, it's basicly just like any other CMS, the backend of the application is the umbraco "backoffice", basicly just an application hidden away in a folder called "~/umbraco/"
This folder has a custom membership provider configured in the web.config.
The frontend site authenticates users automaticly using windows authentication with a role/group restriction. And this is pretty fast, no problems there.
But when i try to access the umbraco folder, which is configured to enable anonymous access, IIS just hangs for at least a minute, before sending me to the login page.
And after the initial hang, i am able to browse the backend fine, but if i leave the backend, and go to the frontend of the application, and then back to the backend, i get the same hanging again. etc.
I tried debugging the code from visual studio, but all i get is some obscure disassembly, which i am unable to make any sense of.
EDIT: This is very odd, as requesting the folder "umbraco" is very slow, but after waiting and being redirected to "umbraco/login.aspx", refreshing this page, or any other page in umbraco is not slow at all. But requesting the folder "umbraco/" is still very slow.
Fiddler
ServerGotRequest: 10:09:21.352
ServerBeginResponse: 10:11:11.961
GotResponseHeaders: 10:11:11.961
ServerDoneResponse: 10:11:11.961
After the ServerGotRequest, something is making IIS hang.
I will try and create another folder with the same configuration, and see if this also happens then.
Has anyone got any clues to what might cause this?
Thanks :)

Losing Session information after publishing an ASP.NET Website on IIS

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.

Do changes to an asp page in classic asp require an iisreset?

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.

How to show maintenance page during deployment?

I want to plan a schedule maintenance down time on one of my production asp.net website hosted on IIS windows server 2003.
I think this is the preferred behavior:
All request to http://www.x.com including www.x.com/asb/asd/ will be redirected to a notification page (site is currently down. come back later)
The maintenance will take around an hour. how do I ensure for having this redirection to maintenance page to have the least impact to SEO/google ranking
Preferrably I want to be able to quietly test the production site before it goes back 'live'
Preferrably I dont want to rely on pointing DNS elsewhere.
To make it simple please pretend that I don't have any other hardware in front of the web servers (i.e load balancer, firewall etc)
An idea would be:
to create another app on the same web server
create httpmodule or httphandler to handle any url request and 302 redirect them to the maintenance page
Thanks
Try putting App_Offline.htm to the root directory.
copy an app_offline.htm file to the webroot
http://weblogs.asp.net/scottgu/archive/2005/10/06/426755.aspx

How to put an asp.net application into offlince/maintenance mode?

I've developed my first web application which, surprisingly, is getting very popular.
Because the website is now live, I have a hard time doing some changes, in fear some people are still logged in and are using the application.
I wish to avoid having a duplicated instance of the web application for testing.
Is there any way to put the website in 'maintenance mode' with only me having access to it? Like redirecting to a page with some info, telling its in maintenance mode.
I wish to avoid having a duplicated
instance of the web application for
testing.
That's your problem right there. For anything but the most trivial sites, you should have a staging or development instance. You should be using source control and have a script to update the main instance.
You can simply drop a file called app_offline.htm in the root of your website and ASP.NET will automatically route all traffic to this page. This file can contain any HTML you wish indicating that your site is down for a short period due to maintenance.
For more information please read App_Offline.htm and working around the "IE Friendly Errors" feature:
The way app_offline.htm works is that
you place this file in the root of the
application. When ASP.NET sees it, it
will shut-down the app-domain for the
application (and not restart it for
requests) and instead send back the
contents of the app_offline.htm file
in response to all new dynamic
requests for the application. When
you are done updating the site, just
delete the file and it will come back
online.
This is the answer to your question:
http://www.codeproject.com/Tips/219637/Put-the-website-in-Maintanance-Mode-Under-Construc
There's no such built-in functionality in ASP.NET except app_offline.htm which doesn't quite fit your needs because even you will be denied access to the site. You have to build it on your own but this is best done on the routers and load balancers level than at the application level. Of course this will depend on your network architecture.
Besides building a dev replica of your website to build patches and fixes on, couldn't you just announce a site closing for maintenance several days in advance? I'm not a web programmer, but you might want look into what Hattrick, a popular online soccer management, does for maintaining their site. They use a notification system on the homepage, after users sign-in, that announces when maintenance will be taking place (usually late at night in Europe where a large portion of the players and all the devs are located) and they close down the website for a couple of hours. When they take the site down they post a page, using the same style as the rest of the site, and provide an estimate of when it will be up and running again. Simple, elegant, and when coupled with the long forewarning it seems to do a good job placating the user base.
Give users a long heads up that planned maintenance is scheduled to take place and give them some idea what it is for and most people will be able to accommodate the down time. Nothing is more frustrating than purposefully going to a web app that was up and running 10-20 minutes ago to find it suddenly unavailable and down for maintenance.
Try app_offline.htm ??
What version of ASP.NET? I'm sure there are a million more elegant ways of doing this, but you can change the Default Document in IIS to redirect to Maint.html (or similar).

Resources