Asp.net 您能否命名w3wp.exe的实例,使其显示在“附加到进程”中?
我在IIS下运行多个进程,调试时很难知道要附加到哪个进程。是否可以通过编程方式设置进程的“标题”,以便在Visual Studio的“附加到进程”窗口中标识该进程?最好更改进程的名称,以便知道要附加到哪个进程。可以使用此VS宏根据应用程序名称附加到工作进程。唯一的技巧是需要将Microsoft.Web.Administration.dll从C:\Windows\System32\inetsrv复制到%PROGRAMFILES(x86)%\Microsoft Visual Studio 10.0\Common7\IDE\PublicAssemblysAsp.net 您能否命名w3wp.exe的实例,使其显示在“附加到进程”中?,asp.net,iis,Asp.net,Iis,我在IIS下运行多个进程,调试时很难知道要附加到哪个进程。是否可以通过编程方式设置进程的“标题”,以便在Visual Studio的“附加到进程”窗口中标识该进程?最好更改进程的名称,以便知道要附加到哪个进程。可以使用此VS宏根据应用程序名称附加到工作进程。唯一的技巧是需要将Microsoft.Web.Administration.dll从C:\Windows\System32\inetsrv复制到%PROGRAMFILES(x86)%\Microsoft Visual Studio 10.0\
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
然后:
在IIS 7.5中,IIS将使用应用程序池的名称自动为每个应用程序池创建帐户
Sub AttachToMyApp()
AttachToWorkerProcess("MyApp")
End Sub