Wednesday, December 10, 2008

Deleting subdirectory restarts AppDomain

When you deletes a subfolder either manually or programatically from the application root folder of IIS, the ASP.NET runtime automatically restarts AppDomain. To fix this, we will need to turn off the folder monitoring in the Application_Start of the Global.asax.vb, this does not apply on bin folder.

Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs)


End Sub

Private Sub StopMonitorFolderChange()

Dim p As System.Reflection.PropertyInfo = GetType(System.Web.HttpRuntime).GetProperty("FileChangesMonitor", _

System.Reflection.BindingFlags.NonPublic Or System.Reflection.BindingFlags.[Public] Or System.Reflection.BindingFlags.[Static])

Dim o As Object = p.GetValue(Nothing, Nothing)

Dim f As System.Reflection.FieldInfo = o.[GetType]().GetField("_dirMonSubdirs", _

System.Reflection.BindingFlags.Instance Or System.Reflection.BindingFlags.NonPublic Or System.Reflection.BindingFlags.IgnoreCase)

Dim monitor As Object = f.GetValue(o)

Dim m As System.Reflection.MethodInfo = monitor.[GetType]().GetMethod("StopMonitoring", _

System.Reflection.BindingFlags.Instance Or System.Reflection.BindingFlags.NonPublic)

m.Invoke(monitor, New Object() {})

End Sub


issue C#: Delete directory kills session

blog comments powered by Disqus