This post will help you when you want to identify which W3WP belongs to which application. It comes in handy when we need to debug Visual Web Parts and Event Receivers deployed as Farm Solutions. The basic approach requires the user to open Visual Studio, attach the W3WP processes and refresh your page to start debugging.
Well, it’s pretty common in our daily life tasks (not so much since we all should move to the Client-side of the force) to have more than one W3WP available to attach. Usually we have one for your site, other for SharePoint Web Services, another for the SharePoint Central Admin and even more for any other Application Pool process being used in your Server.
But if you want to attach to just one process and make Visual Studio more performatic and responsive, how can you do that?
Just follow the steps in this post!
Preparing the project to be debugged in the correct W3WP process
First, you have to ensure that URL for the SharePoint site is correct. You can find it in the Project Properties, in the Site URL field:
Also you need set the project Compilation as Debug, not Release.
Once everything is okay, just deploy the solution.
Reload the page where the Web Part is being used, just to check if the Web Application is running.
Attaching to the process which belongs to the application
Insert a breakpoint where you want to debug.
Open the DEBUG menu in the topbar and click in Attach to Process.
A screen with the Windows processes will be opened. Check the Show processes from all users option.
Usually, the desired w3wp process is the first one on the list. But if you need to ensure that you are attaching to the right one, just open the Command Prompt as Administrator and paste the command below.
cd C:\Windows\System32\inetsrv
Appcmd list wp
pause
Debugging your Web Part with the correct W3WP process
This command will list every W3WP process and its respective name. Once you locate the right W3WP process ID, you can attach to it and start debugging without any problem.
If you have any doubt about the steps I’ve listed, please let me know in the comment section. Hope it helped you on learning how to identify which W3WP belongs to which application
Happy coding!
References:
What is w3wp.exe?
Debugging Web Parts
Tutorial top para quem está iniciando, ainda mais com o truque de selecionar a w3wp correta. Isso faz com que a demora diminua na hora de debugar e que o debug não se perca, que é o que muitas vezes ocorre quando selecionamos todos os processos.
This comment has been removed by the author.