In VS2010, is there a way to know which application pool a given w3wp.exe is serving, to then decide to attach the debugger to?

佐手、 提交于 2019-12-09 01:52:44

问题


So I'm debugging some websites (one from trunk, one from branch) running locally, in separate apppools. I have trunk and branch solutions open in two VS instances. I'd like to debug trunk in one, and branch in the other. I'd like to know if there's a way to know which application pool each w3wp.exe is serving, to know which one is which when attaching the debugger.

Update: the point of this is to write a macro within VS to then let me have a button (per app-pool that is interesting) which will be clickable to attach the debugger to. So solutions should preferably not involve other programs.

Update2: this is on Windows 7 against IIS7.


回答1:


Another option would be the WADA - W3WP Advanced Attacher available in the Visual Studio Gallery. I found it by searching in the Online Gallery of Extension Manager for "attach worker".




回答2:


Below is my core macro. Write a few one-line subs calling it, like AttachToW3wp("DefaultAppPool") naming each app pool you’re interested in, and make buttons and hotkeys for them.

    Private Sub AttachToW3wp(ByVal appPoolName As String)
    Const processName As String = "w3wp.exe"
    Dim userName As String = String.Format("IIS APPPOOL\{0}", appPoolName)

    Try
        Dim debugger As EnvDTE90.Debugger3 = CType(DTE.Debugger, EnvDTE90.Debugger3)
        'debugger.DetachAll()

        Dim transport As EnvDTE80.Transport = debugger.Transports.Item("Default")
        Dim qualifier As String = Environment.MachineName '= My.Computer.Name
        Dim engines(3) As EnvDTE80.Engine
        engines(0) = transport.Engines.Item("Managed")
        engines(1) = transport.Engines.Item("Script")
        engines(2) = transport.Engines.Item("T-SQL")

        Dim successMessage As String = String.Empty
        For Each process As EnvDTE80.Process2 In debugger.GetProcesses(transport, qualifier)
            With process
                Dim fi As New System.IO.FileInfo(.Name)
                If fi.Name = processName AndAlso (String.Compare(.UserName, 0, userName, 0, Len(userName), True) = 0) Then
                    If .IsBeingDebugged Then Throw New Exception(String.Format("{0} {1} is already attached to a debugger.", processName, userName))

                    process.Attach2(engines)
                    successMessage = String.Format("Attached to {0} for {1} ({2})", processName, userName, .ProcessID)

                    Exit For
                End If
            End With
        Next

        If successMessage = String.Empty Then
            Throw New Exception(String.Format("{0} {1} not found.", processName, userName))
        Else
            Trace.WriteLine(successMessage)
        End If

    Catch ex As System.Exception
        MsgBox(ex.Message)
    End Try
End Sub



回答3:


Look at the answers to this question. There are built in scripts you can run from a command window to do this.




回答4:


If you can execute a request on each branch, you could use something like Process Explorer or Task Manager to see which ID is which possibly as one may be taking up CPU cycles that is currently processing a request assuming you can get such separation.




回答5:


You can use task manager to view the user name under which the process is running (which in general is the same as the application pool name) and the process ID, but you have to turn on these columns in task manager, and also the process name has to be the same as the application pool (which is the default as far as I know).
Also note that all methods listed on this page might only display the processes that are currently running, which means that if your particular process has shut down due to idle time you have first to use the site in order to bring the process up in the list, and in your case it means you should first access all sites to make sure that the process associated with them is runing.



来源:https://stackoverflow.com/questions/2654406/in-vs2010-is-there-a-way-to-know-which-application-pool-a-given-w3wp-exe-is-ser

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!