I am having a problem with my Visual Studio 2008 debugger not attaching to the root of the default website when I run from within the enviroment. I have an .NET 3.5 Web Application project running on VS 2008 SP1. I have set the project to "Use Local IIS Web server" with a path of "http://localhost/". I am able to create the Virtual Directory and the application compiles fine. My problem is that when IE launches the debugger is not connected. I am able to "Attach to Process" and choose "w3wp.exe" and it will debug just fine. This is a PITA and I was curious if anyone knew why this will not automatically attach? I used to run this exact same project under a VD and never had an issue with the debugger not attaching. Thoughts?
Is web applications at the root of your website and at your virtual directory is completely identical?
Differences of behavior may be result of incorrect debug settings for your web site project. There are special options for different ways of debugging. One of them is instant attaching of debugger and waiting for external call to website (this is the one you possibly need).
Differences between web.config and IIS configurations may also be the reasons of different behavior.
I use this macro in VS which I wire up to a shortcut key in Visual Studio, it basically does what works for you, attach to w3wp.exe with the debugger. As I had similar issues with the auto attaching not exactly working the way I expected on occasions. For me this works a treat. I also don't like IE firing up automatically as I usually test in Firefox. So this macro doesn't trigger IE autostart which I like.
Imports System
Imports EnvDTE
Imports EnvDTE80
Imports EnvDTE90
Imports System.Diagnostics
Public Module AttachToWebServer
Public Sub AttachToWebServer()
Dim AspNetWp As String = "aspnet_wp.exe"
Dim W3WP As String = "w3wp.exe"
If Not (AttachToProcess(AspNetWp)) Then
If Not AttachToProcess(W3WP) Then
System.Windows.Forms.MessageBox.Show(String.Format("Process {0} or {1} Cannot Be Found", AspNetWp, W3WP), "Attach To Web Server Macro")
End If
End If
End Sub
Public Function AttachToProcess(ByVal ProcessName As String) As Boolean
Try
Dim ProcessFound As Boolean = False
Dim dbg2 As EnvDTE80.Debugger2 = DTE.Debugger
Dim trans As EnvDTE80.Transport = dbg2.Transports.Item("Default")
Dim dbgeng(10) As EnvDTE80.Engine
Dim indexer As Integer = 0
For Each myEngine As Engine In trans.Engines
'Possible values here could be "T-SQL","Native","Managed","Workflow" "Managed/Native", "Script"
If myEngine.Name.Equals("Managed") Then
dbgeng(indexer) = myEngine
indexer += 1
End If
Next
Dim processes As EnvDTE.Processes = dbg2.GetProcesses(trans, "localhost")
For Each Process As EnvDTE80.Process2 In processes
If Process.Name.Contains(ProcessName) Then
Process.Attach2(dbgeng)
ProcessFound = True
End If
Next
Return ProcessFound
Catch ex As System.Exception
MsgBox(ex.Message)
End Try
End Function
End Module
The problem I was having was related to the fact that I had a tag in my web.config that surrounded my tag. This evidently causes the debugger to attach and then error out immediately without any sort of warning or error. Here is the article I used to figure this out: