Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I have an ASP.Net application that performs some database initialization during Application_Start in Global.asax. I'm using IIS Express to debug the application.

I find that if I stop debugging, clear the database, and restart again, the Application_Start code does not get called and my database is not initialized properly, so my application fails. This is because the IIS Express instance is still running after debugging stops. Rather than restarting it, Visual Studio appears to be attaching to the existing process.

Is there a way to change this behavior such that starting a new debugging session always restarts the application process in IIS Express (or resets the application pool in regular IIS)?

Alternatively, is there a way to force IIS Express to shut down when the debugging session ends?

I did find that if I check "Enable Edit and Continue" from the Web dialog in the project settings, that it has the side effect of stopping IIS Express when debugging ends. But I'm not sure I want to introduce the side-effects of Edit and Continue just for the purposes of stopping IIS Express. Surely there's a better way?

Not sure if it matters, but this is VS2012.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
626 views
Welcome To Ask or Share your Answers For Others

1 Answer

Unfortunately it's not achievable through configuration. I may propose you another trick, but it's up to you to decide whether it's better than yours or not :)

You may create a post-build event which changes the timestamp of a web.config file. I used a touch.exe tool from http://www.stevemiller.net/apps/. You also need to set the "Run the post-build event" to Always. So your "Build Events" configuration may look as follows:

enter image description here

With this option set anytime you start the debugger, web.config timestamp is getting updated causing application restart (application appdomain reload) on the first request - but at this point you are already attached to this process so your Application_ event breakpoints should work.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...