Thursday, May 27, 2010

Update MSDN Article: Deploying ASP.NET Web Applications in the Windows SharePoint Services 3.0 _layouts Folder

Hi Folks,

In this post, I'd like to add more updates/Tips to the posted MSDN article with title:

"Deploying ASP.NET Web Applications in the Windows SharePoint Services 3.0 _layouts Folder"
Article url:

The article is going to work fine if you are building ( with limitations ) that is targeting .NET framework 2.0, if you are trying to build and follow the steps on an ASP.NET application that is targeting .NET Framework 3.0 or 3.5 ( specially if your application has AJAX and Silverlight modules on it) then here is the changes/Tips that you might tackle and change:

1) The article doesn't tell you how to have a page that's rendered correctly in your VS.NET while development, the trick on this, do the following:
a) create a folder in your application called _layouts, and copy the application.master file from LAYOUTS folder and paste it on _layouts folder.
b) Now the page will render correctly in VS.NET.
c) You won't be able to build your website since the application.master has a lot of usercontrols and components that doesn't exist in your application.
d) to fix this, simply remove all usercontrols that you have in the application.master and you then be able to compile and build your website.
e) we added application.master just because to have our pages render correctly in our VS.NET IDE and to enrich the design experience of our pages and user controls.
d) As a best practices, no need to hard code the master page name in your code, simply replace the code in the OnPreInit event to the following:

// Old code in the article:
SPWeb Web = SPContext.Current.Web;
string strUrl = Web.ServerRelativeUrl+"/catalogs/masterpage/GamePoint_ThemeBlueDefault.master";
this.MasterPageFile = strUrl;

// New code:
SPWeb Web = SPContext.Current.Web;
this.MasterPageFile = Web.MasterUrl;

The above code will assign the the site masterpage to the custom page. and no need to specify the name of the master page, and this add a major flexibility to your solution specially if you provide your client with different custom master page in your sharepoint site ( as in my case ).

2) The article is telling you just to comment the authentication section in the web.config, this is not true 100%, what you suppose to do is to remove any attribute that exist on the web.config of the sharepoint site otherwise you will get duplicate entry error. To fix this:

a) remove any duplicate entries on your web.config file from your application.

b) no need to have web.config in your site if you don't have any custom entries on your site. and in this case, your site will run under the configuration of the sharepoint site that exists in sharepoint site folder.

With these 2 tips you will be able to build any 2.0/3.0/3.5 application with no limitations and make use of the full functionality of VS.NET Design tools.

Hope this helps.

Mostafa arafa

No comments: