Restart IIS site from MVC

I am looking for a way to restart the current website (from the admin page) from an MVC controller, with C # .NET

Why do I need it? I have an error on the website, but this only happens after the website starts a random amount of time, which is very difficult to find, in the meantime I still need a remote way to quickly reload the website from my phone.

+4
source share
3 answers

An ASP.NET application may restart because there are really many reasons. This probably happens more often than you think. The ASP.NET web application will restart due to:

  • Web.Config. , .
  • machine.config, web.config.
  • /bin. , , /bin.
  • App_Code. , App_Code .
  • Global.asax, , web.config.
  • App_LocalResources
  • App_GlobalResources
  • App_WebReferences
  • , numRecompilesBeforeAppRestart machine.config. - 15. ASP.NET . ( ) , - . . , , .
  • . , Web.config Global.asax. , , -.
  • IIS , - .
  • -
  • IIS - ( 20 ). , IIS , . , .

.

  • UnloadAppDomain , .

    System.Web.HttpRuntime.UnloadAppDomain()

  • date gloabl.asax web.config,

    File.SetLastWriteTimeUtc(MapPath("~/global.asax"), DateTime.UtcNow); File.SetLastWriteTimeUtc(MapPath("~/web.config"), DateTime.UtcNow);

+2

.bat IISresart.bat

iisreset

iisreset , IIS.

ASP.net

            string str_Path = Server.MapPath(".") + "\\IISresart.bat";
            ProcessStartInfo processInfo = new ProcessStartInfo(str_Path);
            processInfo.UseShellExecute = false;
            Process batchProcess = new Process();
            batchProcess.StartInfo = processInfo;
            batchProcess.Start();

IIS.

. - asp.net. MVC. processInfo.CreateNoWindow = true;

+3

, , , / ( ) dummy.dll bin.

you can name this dll file as you want, but by creating / deleting it, it will restart the entire application (pool) and fix your problem.

The beauty of this solution is that you do not need special permissions for your web application.

+3
source

All Articles