Click here to Skip to main content
11,500,844 members (79,998 online)
Click here to Skip to main content

Tagged as

Recycling application pools on shared hosting

, 5 Oct 2011 CPOL 7.6K 1
Rate this:
Please Sign up or sign in to vote.
You may find that when you upload new code or assemblies, your content doesn't refresh.

I recently signed up for ASP.NET hosting on a server that uses LAMP as a front-end and proxies ASP.NET requests to a back-end IIS server. The setup actually works fine, and with a few hiccups (ASP.NET routing doesn't work, so I had to configure mod_rewrite instead), my site is working OK.

One of the advantages to hosting on a pure IIS server is that it monitors filesystem activity, and when a page or assembly is modified, it reloads that file.

This doesn't work with an Apache front-end, so the quickest workaround is to touch web.config.

That's fine for forcing a re-read of a file, but if you need to clear the cache, or you have static variables that are persisting data and you want them cleared, you need to unload the running assembly.

Alberto Venditti[^] wrote an excellent article, Recycling IIS 6.0 application pools programmatically[^] which proposes one programatic way to recycle the application pools; however, his approach requires knowing the name of the site as it is configured in IIS, and some other information to which you might not have access.

My approach is simpler, and consists of a short Web Form:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="recycle.aspx.cs" Inherits="utility_recycle" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
       "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Unload AppDomain</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>Recycling... <%= message %></div>
    </form>
</body>
</html>
using System;
using System.Web;
 
public partial class utility_recycle : System.Web.UI.Page
{
    public string Message;
 
    protected void Page_Load(object sender, EventArgs e)
    {
        try
        {
            HttpRuntime.UnloadAppDomain();
            Message = "Success";
        }
        catch (Exception ex)
        {
            Message = "Failed: " + ex.Message;
        }
    }
}

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Yvan Rodrigues
President Red Cell Innovation Inc.
Canada Canada
Yvan Rodrigues has 25 years of experience in information systems and software development for the manufacturing sector. He runs Red Cell Innovation Inc./L'innovation de Globules Rouges, a consulting company focusing on efficiency and automation of manufacturing and business processes for small businesses, healthcare, and the public sector. He is a Certified Technician (C.Tech.), a professional designation granted by the Institute of Engineering Technology of Ontario (IETO).

Yvan draws on experience at Mabel's Labels Inc. as Manager of Systems and Development, and the University of Waterloo as Information Systems Manager.

Yvan supports open-source software. He is a committer for SharpKit (C# to Javascript cross-compiler) and WebIssues (Issue/Ticket Management System), TinyMCE (JavaScript editor), and contributes to MySQL, Ghostscript, iTextSharp, Bacula, FreeBSD, and Xamarin.

Yvan's consumer-focused apps can be found in the Windows Store, Apple App Store, and Google Play marketplace.
Follow on   LinkedIn

Comments and Discussions

 
-- There are no messages in this forum --
| Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.150520.1 | Last Updated 5 Oct 2011
Article Copyright 2011 by Yvan Rodrigues
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid