简体   繁体   中英

How to debug code executed at application's startup if application is hosted in IIS and starts when IIS does?

I have a .NET application which is server framework and it is hosted in IIS and it starts when IIS does.

To debug the framework I attach to the client process by Visual Studio. It works for normal debugging, but now I want to debug section when framework loads its configuration from xml files (it is handled by C# code). It does it only once when application starts so exactly the same time the IIS starts. I am not faster than IIS with attaching my solution.

If I attach framework to the client process then reset the IIS the debugger will be detached.

How to handle such problem?

Bad solution: The only way may work is to put a very long Thread.Sleep at the beginning of the app and then attach quickly.

Add

System.Diagnostics.Debugger.Launch();

to Application_Start . You'll get a popup asking you if you want to debug the website, and if you click OK, you'll be taken to Visual Studio in debug mode, paused at that line.

Try changing your project to using "IIS Express" instead of Local IIS - when you then start the app, Visual Studio will start the IIS Express as well, with the debugger already attached to the service.

You can change the setting by right clicking on the project => choose Properties => click the Web tab => find IIS Express in the combobox under "Servers".

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM