Some thoughts on programming stuff

Identify which W3WP belongs to which application

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:

SharePoint project with Custom Web Part - Identify which W3WP belongs to which application
SharePoint project with Custom Web Part

Also you need set the project Compilation as Debug, not Release.

Configurations for debugging - Identify which W3WP belongs to which application
Configurations for debugging

Once everything is okay, just deploy the solution.

Deploying a SharePoint solution - Identify which W3WP belongs to which application
Deploying a SharePoint solution

Reload the page where the Web Part is being used, just to check if the Web Application is running.

Rendered Web Part - Identify which W3WP belongs to which application
Rendered Web Part

Attaching to the process which belongs to the application

Insert a breakpoint where you want to debug.

Simple Web Part code - Identify which W3WP belongs to which application
Simple Web Part code

Open the DEBUG menu in the topbar and click in Attach to Process.

Visual Studio's Debug Menu - Identify which W3WP belongs to which application
Visual Studio’s Debug Menu

A screen with the Windows processes will be opened. Check the Show processes from all users option.

Attach to Process window - Identify which W3WP belongs to which application
Attach to Process window

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

W3WP available - Identify which W3WP belongs to which application
W3WP available

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.

Breakpoint was reached - Identify which W3WP belongs to which application
Breakpoint was reached

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

2 Comments

  1. Wagner Lemos Duarte

    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.

  2. o

    This comment has been removed by the author.

Leave a Reply

Your email address will not be published. Required fields are marked *

© 2024 wiliammbr's blog

Theme by Anders NorenUp ↑