Issue/Problem:
If you are deleting a subdirectory within your application, your app domain will restart. This removes all session data.
Solution:
To alleviate this issue, only add/remove directories outside your application home directory.
OR
When you delete a subfolder either manually or programmatically 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)
StopMonitorFolderChange()
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