Restart ASP.NET Application Programatically

A lot of developers are asking how to restart the ASP.NET application or recycle the ASP.NET process without the need to modify the content of web.config file or changing its name.

You can use the  HttpRuntime.UnloadAppDomain() which will terminate the application and of course remove all the session objects for all users the next time a request is being received.


Create a dummy web application, drag and drop two buttons. and use some like below

private void Page_Load(object sender, System.EventArgs e)


// Put user code to initialize the page here




private void Button1_Click(object sender, System.EventArgs e)

private void Button2_Click(object sender, System.EventArgs e)

When you click Button2, you will have object reference not set to an instance of an object error which indicates that Session["ASP"] is equal to null.

Hope this helps

Published 25 July 2008 08:21 PM by haissam


# BasharKokash said on 26 July, 2008 02:40 AM

Thanks very much

# xxxd said on 27 July, 2008 08:19 PM

indeed. This is helpful

# Sergio said on 15 November, 2009 06:29 PM

Thanks for a hint!

# How to restart an ASP.NET application | Rob Seder's Blog - ARCHIVE said on 16 December, 2013 07:43 PM

Pingback from  How to restart an ASP.NET application | Rob Seder's Blog - ARCHIVE

This site



This Blog



  • MaximumASP