What makes you think your controller is running before Application_Start? Is it just because you're in the debugger and you don't see the breakpoint in App_Start?
application start fires every time there is a app domain recycle. you can f5 several times before a recycle is done. just new versions of the dlls are loaded (and the old one stay in memory).
also because of this behavior and the way recycles are done, the app start in new new domain can happen before the app end in the old domain.
hc1
Member
199 Points
231 Posts
How to ensure Application_Start run before everything else?
Mar 27, 2012 03:27 PM|LINK
I notice that the default action of the default controller will run first before Application_Start in Global.asax.cs.
Where should I put my initialization stuff to ensure that it runs before any web page starts loading?
Thanks.
adamturner34
Contributor
3824 Points
963 Posts
Re: How to ensure Application_Start run before everything else?
Mar 27, 2012 03:28 PM|LINK
In Application_Start
BrockAllen
All-Star
27432 Points
4890 Posts
MVP
Re: How to ensure Application_Start run before everything else?
Mar 27, 2012 03:40 PM|LINK
What makes you think your controller is running before Application_Start? Is it just because you're in the debugger and you don't see the breakpoint in App_Start?
DevelopMentor | http://www.develop.com
thinktecture | http://www.thinktecture.com/
ignatandrei
All-Star
134491 Points
21566 Posts
Moderator
MVP
Re: How to ensure Application_Start run before everything else?
Mar 27, 2012 04:00 PM|LINK
Application_Start runs ONCE , prior to any request.
For your needs( runs before any ACTION ) you can intercept Application_BeginRequest( old style) or make a GlobalFilter( MVC style)
hc1
Member
199 Points
231 Posts
Re: How to ensure Application_Start run before everything else?
Mar 28, 2012 12:31 AM|LINK
I was running in VS 2010 and debugger.
For every F5, sometimes Application_Start runs, sometimes it doesn't.
If I do a project Clean, F5 will cause Application_Start to run before anything else.
So, Application_Start runs once per XXXX. What is XXXX? IIS instance? Worker thread?
bruce (sqlwo...
All-Star
36644 Points
5432 Posts
Re: How to ensure Application_Start run before everything else?
Mar 28, 2012 01:47 AM|LINK
application start fires every time there is a app domain recycle. you can f5 several times before a recycle is done. just new versions of the dlls are loaded (and the old one stay in memory).
also because of this behavior and the way recycles are done, the app start in new new domain can happen before the app end in the old domain.
ignatandrei
All-Star
134491 Points
21566 Posts
Moderator
MVP
Re: How to ensure Application_Start run before everything else?
Mar 28, 2012 04:56 AM|LINK
Running in VS Cassini is not reliable. Try IIS.