开发者

Reset IIS on ASP.NET site when an error occurres

i have an ASP.NET web site that on some very rare occasions has an error that causes a lot of requests to fail. the error is caught and logged in the OnError override of my base class for all pages so i know when the error occurred.

since this error is very rare i want to reset the iis when it occurres so the site will return to function normally.

my开发者_JAVA百科 question: on the OnError code below, how can i cause the IIS to reset? i can run iisreset or can cause the iis to crash using something like System.Environment.Exit(-1). what is there a preferred method to reset the iis?

    Protected Overrides Sub OnError(ByVal e As EventArgs)
        LogException(Server.GetLastError())
        MyBase.OnError(e)
    End Sub


Firstly, as pointed out by other, you need to restart the ASP.NET application and not IIS (web server). Two ways to achieve this could be

  1. To touch (modify) web.config (similar alternative is to touch/modify bin folder)
  2. To ask AppDomain to unload (using HttpRuntime.UnloadAppDomain)

Check this article that discusses this approach.

I would also suggest you to consider period application pool recycling (possible from IIS configuration) as alternative. an

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜