Although VS 2005 provides awesome support for developing Web parts one of the pain points can be debugging a web part, some tips on how to debug a web part :

 

Two methods:

 

  1. Direct:  Attach debugger to the w3wp.exe process that hosts SharePoint.
  2. Automatic: make the url of a given page as the Application Start in the project properties.

 

Debugging can be difficult if the web part is published in GAC (IIS needs to access the pdb file for the web part assembly to load debug symbols) so while in development environment it is more useful to deploy the web part to the Bin directory and use manual Installation instead.

 

Enabling Debugging in the SharePoint Web.Config file

Note: Make sure these flags are unset when moving to the production server.

 

Set the CallStack attribute to true. This allows for the callstack and exception to be displayed.

 

<SharePoint>

    <SafeMode MaxControls="200" CallStack="true" DirectFileDependencies="10" TotalFileDependencies="50" AllowPageLevelTrace="false">

      <PageParserPaths>

      </PageParserPaths>

    </SafeMode>

……………….

……………….

</SharePoint>

 

Change the Site's trust level to either Medium or Full (if the assembly is in GAC then the Trust level is automatically Full Trust), by default the trust level is WSS_Minimal

<system.web>

……………….

<trust level="WSS_Medium" originUrl="" />

……………….

……………….

<system.web>

 

Thats it !! .. The next time the web part is loaded the Sharepoint website will break into the code.

 

For more infrormation: http://msdn2.microsoft.com/en-us/library/ms916837.aspx#sharepoint_debugwebparts_topic4