Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 191 Vote(s) - 3.75 Average
  • 1
  • 2
  • 3
  • 4
  • 5
ASP.NET restarts when a folder is created, renamed or deleted

#1
**UPDATE -- process to replicate issue:**

1) Create a website project at **c:\projects\restart-demo**

2) Add default web.config and a dummy aspx page **test.aspx**

3) Map IIS to point to the root folder **c:\projects\restart-demo**

4) Monitor application restarts using perfmon, health monitoring, tracking in global.asax Application_End, etc.

5) Request page in browser

[To see links please register here]


*application start*

6) Create new folder **c:\projects\restart-demo\asdf**

*application end*

7) Request page in browser

[To see links please register here]


*application start*

8) Rename folder **c:\projects\restart-demo\asdf** to **c:\projects\restart-demo\asdf1**

*application end*


**end update**

We are using a back-end CMS to generate files and folders in an ASP.NET site.

Users are able to create/modify/delete files and push these out to the web farm.

One problem we have noticed:

> **When the user creates, renames or deletes a folder**, it causes the App
> Domain to restart. As a consequence,
> session, cache, etc. are all lost.

Note it doesn't need to be a special folder like /bin or /App_Code either.

Is there any way to prevent this behavior?

It is really hampering performance for two reasons:

- Cache is dumped when app domain restarts
- App domain needs to be re-built after restart

Reply

#2
By default an asp.net application will restart every 15th time a file changes within it's virtual directory, this is to outweigh partial recompilations and their memory weight vs overall performance...you can change this behavior, but memory use may rise and performance will drop off over time.

To do this, set the [numRecompilesBeforeAppRestart attribute on the compilation element][1], your web.config would have en element like this:

<configuration>
<system.web>
<compilation numRecompilesBeforeAppRestart="15">

The default is 15, you can change it to whatever you want, read the link for more info. However, **it's this way for a reason**, it's not recommended to have your dynamic content inside the app's virtual directory, best to have it beside it or somewhere else entirely.


[1]:

[To see links please register here]

Reply

#3
Enable [ASP.NET Health Monitoring](

[To see links please register here]

) and look in the event log to see why the AppDomain restarted.

---

I bet this is because you've used a web site project, instead of a web application project. Try to reproduce this with a web application project.

Also, do you have any anti-virus or indexing software running? Such software notices when folders are created and/or modified.
Reply

#4
This code appears to resolve the issue, when added to Application_Start() in Global.asax:

PropertyInfo p = typeof(System.Web.HttpRuntime).GetProperty("FileChangesMonitor", BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static);
object o = p.GetValue(null, null);
FieldInfo f = o.GetType().GetField("_dirMonSubdirs", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.IgnoreCase);
object monitor = f.GetValue(o);
MethodInfo m = monitor.GetType().GetMethod("StopMonitoring", BindingFlags.Instance | BindingFlags.NonPublic);
m.Invoke(monitor, new object[] { });

[To see links please register here]


With these changes, I can create/modify/delete folders without causing the application to restart.

Not clear if this is the best solution -- Don't know if there will be unwanted side effects due to calling StopMonitoring.
Reply

#5
Perhaps a bit late, but storing and handling your temp files in a different folder outside the wwwroot of your application also solves the problem.
Reply

#6
Adding `"fcnMode="Disabled"` to the `<httpRuntime>` settings in the `web.config` disables AppDomain recycling when the contents of the web root folder are altered.
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through