你可以命名一个w3wp.exe的实例,以便它显示在附加到进程吗?

时间:2009-05-01 17:10:21

标签: asp.net iis

我在IIS下运行多个进程,在调试时很难知道我想要附加到哪个进程。您是否可以以编程方式设置进程的“标题”,以便可以在Visual Studio的“附加到进程”窗口中进行标识?

3 个答案:

答案 0 :(得分:2)

最好更改流程的identity,以便了解要附加的流程。

答案 1 :(得分:2)

您可以使用此VS宏根据应用程序名称附加到工作进程。唯一的技巧是你需要将Microsoft.Web.Administration.dll从C:\ Windows \ System32 \ inetsrv复制到%PROGRAMFILES(x86)%\ Microsoft Visual Studio 10.0 \ Common7 \ IDE \ PublicAssemblies。

Private Sub AttachToWorkerProcess(ByVal appName As String)
    Dim targetPid = FindPoolPIDByName(appName)
    If targetPid = -1 Then
        MessageBox.Show("Unable to find a worker process hosting " + appName)
    End If

    Dim processes As EnvDTE.Processes = DTE.Debugger.LocalProcesses

    For Each proc As EnvDTE.Process In processes
        If proc.ProcessID = targetPid Then
            proc.Attach()
        End If
    Next

End Sub

Private Function FindPoolPIDByName(ByVal appName As String) As Integer
    Dim sm As New Microsoft.Web.Administration.ServerManager()

    Dim appPoolName As String = Nothing
    For Each site In sm.Sites
        For Each app In site.Applications
            If String.Equals(app.Path, "/" & appName, StringComparison.OrdinalIgnoreCase) Then
                appPoolName = app.ApplicationPoolName
            End If
        Next
    Next

    If appPoolName Is Nothing Then
        MessageBox.Show("Unable to find application " & appName)
    End If

    For Each wp In sm.WorkerProcesses
        If wp.AppPoolName = appPoolName Then
            Return wp.ProcessId
        End If
    Next
    Return -1
End Function

然后:

Sub AttachToMyApp()
     AttachToWorkerProcess("MyApp")
End Sub

答案 2 :(得分:2)

在IIS 7.5中,IIS将自动为每个appPool创建具有应用程序池名称的帐户。

http://learn.iis.net/page.aspx/624/application-pool-identities/