Friday, November 27, 2009

Using configurations in MOSS Web Parts/ InfoPath browser forms

There are times when we want some values to be configurable. For example, a hyperlink in MOSS web part or an InfoPath browser form must be configurable so that when the artifacts are moved across environments, the link points to correct target.

This can be achieved in simple web.config changes of MOSS web application as follows:
Step 1:
Define a sectiongroup tag under

<sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
</sectionGroup>

Step 2:
Add a corresponding .Settings tag under applicationSettings group we defined

<section name="SampleConfig.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />


Step 3:

Now that we have defined a placeholder, we can define actual configuration settings under it.
<applicationSettings>
<SampleConfig.Properties.Settings>

<setting name="AHyperLink" serializeAs="String">
<value>http://abc</value>
</setting>
</
SampleConfig.Properties.Settings>
</applicationSettings>

Why this works?
Thanks to the ASP.NET infrastructure upon which MOSS is built. The MOSS web application undergoes the same ASP.NET request processing pipeline. Hence, the configurations defined above work. Please note that the highlighted tag names must match for this to work.

Tuesday, November 10, 2009

Remote Debugging in Visual Studio

Overview:
Remote debugger is a tool provided by Visual Studio to debug an application hosted on a different machine.
In local debugging, it is required to have application hosted on the development machine. We attach a debugger to the local process (e.g. W3WP.exe) which hosts the application. The symbol files (.PDB files) location is present on the same machine.
In remote debugging, the application can be hosted on a different machine (or server). Yet, we can debug it as if it is on the local machine.



Key Scenarios where remote debugging is must:
1. Debugging of ASP.NET web applications/Web services right on the server
2. Debugging InfoPath browser forms
3. Debugging of Web Parts deployed on MOSS



Installing Remote Debugger on the server:
Remote debugger setup can be found at ”Program Files\Microsoft Visual Studio 8\Common7\IDE\Remote Debugger” in Visual Studio Setup.
If it is not possible to install the setup on the server, copy and paste following directory to the server:
(Program Files\Microsoft Visual Studio 8\Common7\IDE\Remote Debugger\ x86 (or x64if server is 64 bit) to any location.



In this post, I will explain first scenario:
Remote debugging of ASP.NET web applications/Web services



To remote debug ASP.NET application following setup is required on server and development machine:

Setup on the Server:
Start the remote debugger by double clicking msvsmon.exe located in the Remote Debugger folder.
If you are debugging ASP.NET application, in command prompt type IISAPP.VBS. This will list all the worker processes and their PIDs. Note the Process ID of the worker process to be debugged.
Note: If you are debugging InfoPath form or a MOSS web part, please note the PID of the MOSS web application.



Setup on the development machine:
1. Go to debug -> attach to Process
2. Enter the machine name on which msvsmon.exe is running
3. Select the w3wp.exe with correct PID
4. Click attach



Debugging will start and break points will be hit.


Common Problems in Remote Debugging:
1. Debug Symbols not getting loaded
Solution:


Many times source code gets updated after the build was deployed on the server. Rebuild the source code and redeploy the ASP.NET application.
If this does not help, then
Go to debug -> Modules. This lists all modules.
Right click the module for which symbols are not loaded -> Load symbols