4

I created a simple ASP.NET project and then added cloud deployment descriptor using Visual Studio. Once I do that, Application_Start() method in global.asax file never gets called. In my project, I do lot of initialization such as loading web.config file, loading connection strings, initiailizing cache, etc. I can not put all of them into WebRole.OnStart() method.

Is there any special configuration required to have Application_Start() method in Global class invoked?

Thanks, Prasanna

AvkashChauhan
  • 20,495
  • 3
  • 34
  • 65
phebbar
  • 265
  • 1
  • 3
  • 12
  • Appears to be cross-posted on MSDN: http://social.msdn.microsoft.com/Forums/en-US/windowsazuredevelopment/thread/d1942ee0-71af-4dda-9679-17328c887d93 – user94559 May 22 '12 at 06:16
  • There's nothing special you have to do. It should just work. How do you know Application_Start isn't being called? – user94559 May 22 '12 at 06:17
  • Yes. I put it into both the forums, hoping to get quick response. I put a debug point in Application_Start and it doesnt stop there, where as it stops at WebRole.OnStart() debug point. – phebbar May 22 '12 at 07:22
  • Strange...Inside the Application_Start() method, I set Application property and to my surprise, that is being called. So it appears to be a bug or feature!! - Application_Start() in Global is not called during the debug. But that method is infact called and initialization does happen. So works fine now... – phebbar May 22 '12 at 09:06

1 Answers1

4

As SMARX stated Applicaton_start() is always called however with your Web Role if you have full IIS role then VS2010 debugger does not hit Application_start(). I am writing the detail below on how you can hit BP at Application_Start() in Global.asax.cs:

First you can write Debugger.Break() code in your Application_Start() as below: enter image description here

Now please open your Role Properties > Web and select

  1. Use Visual Studio Development Server settings (I have chosen as shown in image below)
  2. Use Local IIS Web Server

enter image description here

Now debug your application and you will see a message as below to debug W3WP.EXE process

enter image description here

Select Debug option above and then you will see BS JIT Debugger Windows as below:

enter image description here

Once you accept VS JIT debugger launch process, you will see the PB hit in your Applicaton_start() as below:

enter image description here

That's it!!

AvkashChauhan
  • 20,495
  • 3
  • 34
  • 65