ASP.NET - Getting the Virtual Application Root Path for Your Site


I had to blog this here, because I have the need for it every once in a while, but not frequent enough to remember it... :)

A site hosted without a virtual directory: mysite.com/
Returns: "/"

A site hosted from a virtual directory: mysite.com/myVirtualDir
Returns: "/myVirtualDir"

See the MSDN Documentation for more details and code examples.
See the "ASP.NET Web Site Paths" article for more ways to discover paths.


Make Visual Studio Prompt You For Debug Source Code File After Cancelling the First Time

I've run into this problem a few times where I've been given a copy of a dll from another development team that has a PDB file with it... but they forget to send me the source code...

While debugging, I get the prompt for the source code file the PDB has signalled the debugger for (since it doesn't know where to find it initially...) and of course, since I don't have it, I click Cancel.

When you click cancel at this prompt, it adds to a repository in the solution of files NOT to search for. This is annoying, because after that first prompt, you ask the team for the source code so you can go back, expecting the prompt again, and step into the potentially problematic code.

Well, Visual Studio supresses the prompt because of this list within the solution of files not to search for.

"How do I get this back?!" you ask...

Here's the "solution" (get it?!):

The 'Do not search for these source files' dialog

Right-click your solution in Solution Explorer and go to Properties.
Then click on the "Debug Source Files" section under Common Properties.
At the bottom-right of the dialog, there is a "Do not look for these source files:" section. There lies the last-known path to the source-code file (which I assume is provided by the PDB.)
Delete that sucker and Apply/OK out.

Debug again and when you get to the point you want to step into that code again, you will get the prompt and life will be happy again (well, happier, until you fix your bug.)

Happy coding...