How can I programmatically recycle a .net web app's own apppool?

前端 未结 4 1723
故里飘歌
故里飘歌 2021-01-04 11:00

I have a complex server application that uses Nhibernate and Linq2SQL. About 3 times per day the Linq2sql code generates a \"value cannot be null\" exception. Once this happ

4条回答
  •  渐次进展
    2021-01-04 11:15

    The following code will recycle the current site's app pool. You need to add a reference to Microsoft.Web.Administration

    using (ServerManager iisManager = new ServerManager())
    {
        SiteCollection sites = iisManager.Sites;
        foreach (Site site in sites)
        {
           if (site.Name == HostingEnvironment.SiteName) 
           {
             iisManager.ApplicationPools[site.Applications["/"].ApplicationPoolName].Recycle();
             break;
           }
        }
    }
    

提交回复
热议问题