4

I need to restart my mvc4 web application programmatically. But System.Web.HttpRuntime.UnloadAppDomain() doesn't work.

What is the best way to restart asp.net mvc application? Please mind that changing web.config content or folder names doesn't solve my problem.

Cœur
  • 37,241
  • 25
  • 195
  • 267
Mesut
  • 1,845
  • 4
  • 24
  • 32
  • 1
    Why doesn't `System.Web.HttpRuntime.UnloadAppDomain()` work for you? – Darin Dimitrov Jan 25 '14 at 13:28
  • 2
    By restarting the website in IIS. Are you looking to do this from within your MVC application? Can I further ask why you must restart the application? – Mister Epic Jan 25 '14 at 13:28
  • I'm using an output cache like that [CustomOutputCache(DurationApplicationKey = "cacheSql", Location = OutputCacheLocation.Server)], So when database has been changed from admin panel, app will be restarted and values will be taken. – Mesut Jan 25 '14 at 13:32
  • @Darin Dimitrov, I don't know, but My admin panel is classic asp.net and user interface is mvc4. Also you can check this link: http://daron.yondem.com/en/post/d82b6b05-8c59-4136-becd-329156083b75 – Mesut Jan 25 '14 at 13:33

2 Answers2

12

this code work for me. just call it to reload application.

System.Web.HttpRuntime.UnloadAppDomain();

More info

This method will just unload our application. If you just put this method in an ASP.NET web button you are totally done. So when will our application reloaded? Actually if you click your button it will first launch our method and unload application. Further on the web page we are on at that moment will be reloaded as well, because we just clicked a button and the web page should refresh. After launching our method the page refresh process will cause our application to reload as well.

Fred
  • 3,365
  • 4
  • 36
  • 57
1

EDIT - After looking at comment on OutputCache in the question, You can invalidate OutputCache programmatically, Check this out

If still you want to Restart IIS or AppPool then you can follow these resources -

Community
  • 1
  • 1
ramiramilu
  • 17,044
  • 6
  • 49
  • 66