Saturday, March 29, 2008 11:19 PM mikedopp

Resetting your web application or web site without recycling app pool or IIS.

If you don't know by now you can reset your web applications and or web sites with a simple change to the web.config. For example you can FTP(if remote or hosted) to your server and edit the web.config by adding a space or removing a space. Basically you want the application your using editing with think something has changed since you touched the document. Save the form after this has happened and IIS will recycle the application / web site.

This however can be tedious and just well feel like a bit of hacking. So what I have come up with is not rocket science and you most likely do not want in a easy to access area on your web form.

I add this little snippet to a button event on the form. So when ever the site needs a cleansing for what ever reason I push the button of recycle.

public bool RecycleApplication()
   {
       bool Success = true;

       //Method #1
       //   It requires high security permissions, so it may not
       //   work in your environment
       try
       {
           HttpRuntime.UnloadAppDomain();
       }
       catch (Exception ex)
       {
           Success = false;
       }

       //if (!Success)
       //{
       //    //Method #2
       //    //   By 'touching' the Web.config file, the application
       //    //   is forced to recycle
       //    try
       //    {
       //        string WebConfigPath = HttpContext.Current.Request.PhysicalApplicationPath + "\\\\Web.config";
       //        IO.File.SetLastWriteTimeUtc(WebConfigPath, DateTime.UtcNow);
       //    }
       //    catch (Exception ex)
       //    {
       //        Success = false;
       //    }
       //}

       return Success;

   }
   protected void Button1_Click(object sender, EventArgs e)
   {
       RecycleApplication();
   }

 

Once again probably not a standards compliant and not an elegant way of recycling the application / web site. However it does the job.

Filed under: , ,

Comments

# Resetting your web application or web site without recycling app pool or IIS. - Mike Dopp

Pingback from  Resetting your web application or web site without recycling app pool or IIS. - Mike Dopp

# Minimum Permission Required for Assembly

Monday, March 31, 2008 5:52 AM by .NET Developer Notes

Minimum Permission Required for Assembly

# Interesting Finds: 2008.03.31

Monday, March 31, 2008 8:12 PM by gOODiDEA

.NET:Improving.NetPerformanceWithNgen:TheNativeImageGeneratorDefiningRoutesusingRegul...

# Interesting Finds: 2008.03.31

Monday, March 31, 2008 8:13 PM by gOODiDEA.NET

.NET: Improving .Net Performance With Ngen: The Native Image Generator Defining Routes using Regular

# Resetting your web application or web site without recycling app pool

Saturday, September 06, 2008 12:25 AM by DotNetKicks.com

You've been kicked (a good thing) - Trackback from DotNetKicks.com

Leave a Comment

(required) 
(required) 
(optional)
(required)