debugging the inline code of custom layout pages in SharePoint
Have you ever tried to debug the inline code of custom layout pages of a SharePoint site ?. I have tried once and I couldn't able to debug the inline code by just opening it in VS.NET IDE and attaching the w3wp processor to the debugger. Initially I couldn't figure out why it is not able to debug the inline code. After that I have checked debug mode in the compilation tag of web.config, then I found that it was false by default as like this <compilation batch="false" debug="false">
I had just made a change in that web.config file by making the debug="true" and I was able to debug the inline code.
<compilation batch="false" debug="true">
Whenever we create a custom layout page, we have to keep those aspx pages in the location C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\LAYOUTS, now any SharePoint site in that particular SharePoint server can access that page by the following URL. https://<sitename>/_layouts/mycustom.aspx. If we create a custom layout page in the Layouts folder we can't use a separate code behind file as like what we normally use with aspx pages in a asp.net application (though we can create an asp.net application with aspx pages and code behind file and keep it in the layouts folder.).
Now consider we have created a custom layout page with name ‘mycustom.aspx’ and the following inline code.
<%@ Assembly Name="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Assembly Name="System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" %>
<%@ Assembly Name="System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" %>
<%@ Page Language="C#" MasterPageFile="~/_layouts/application.master" Inherits="Microsoft.SharePoint.WebControls.LayoutsPageBase" %>
<%@ Import Namespace="System.Web" %>
<%@ Import Namespace="System.Net.Mail" %>
<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="Microsoft.SharePoint" %>
<script runat="server">
protected override void OnLoad(EventArgs e)
{
try
{
Response.Write(“Hi, welcome to my custom layout page”);
}
catch (Exception ex)
{
}
}
</script>
After that, we are placing it in to the Layouts folder C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\LAYOUTS, now all SharePoint sites in that SharePoint server can access that page as like this, https://<sitename>/_layouts/mycustom.aspx
Now, If you want to debug the inline code of that layout page, please follow the below steps.
- Open the physical folder of that particular SharePoint web application. By default it will be in the following location C:\Inetpub\wwwroot\wss\VirtualDirectories\<Port Number>
- Open the web.config file from that folder and make debug="true" in the compilation tag.[<compilation batch="false" debug="true">]
- Now open the mycustom.aspx page in VS.NET IDE and in browser using the appropriate SharePoint site URL [https://<sitename>/_layouts/mycustom.aspx]
- Attach the w3wp processor to the debugger and refresh the page in browser – now you can debug the inline code by puting a breakpoint
Comments
Anonymous
March 25, 2008
PingBack from http://www.virtual-generations.com/2008/03/25/sharepoint-2007-link-love-03-25-2008-part-deux/Anonymous
January 07, 2009
great post! this was exactly what i needed.Anonymous
January 07, 2009
Thanks Shereen. Good to hear that :)