Developing SharePoint 2007 in ASP.NET Web Application

No.of Views1120
Bookmarked0 times
Downloads 
Votes0
By  Mostafa Elzoghbi   On  08 Jun 2010 07:06:46
Tag : SharePoint , Development and Programming
This article,i will walk through the steps required to create and deploy asp.net web application under _layouts folder in sharepoint 2007
emailbookmarkadd commentsprint

Images in this article missing? We recently lost them in a site migration. We're working to restore these as you read this. Should you need an image in an emergency, please contact us at info@codegain.com

 

Introduction

This post i will walkthrough the steps required to create and deploy asp.net web application under _layouts folder in sharepoint 2007. Also note that this application is different than the MSDN article to build asp.net 2.0 website in sharepoint 2007, since this article only works if you copy the whole project ( with .cs files ) under website folder in layouts directory which is not recommended and not a best practice.

In this article i will go through the steps to create a web application with sharepoint master page and to deploy the web application dll in GAC as well.

1) Open your VS 2008, and select ASP.NET web application template.

2) Add Microsoft.Sharepoint.dll in your project references.

3) Create a folder in your project called _layouts, the purpose of this project is to have a dummy masterpage that let you develop your custom pages with sharepoint site master page and the pages will pick the site masterpage at runtime.

4) To get a dummy application.master, get it from this link:
http://cid-4bc94054914a6469.skydrive.live.com/self.aspx/Blog%20Code/application.master

5) Right click on your project to sign your assembly of the web application, since this dll will be in GAC.

6) Open the default.aspx page that you have and update the following:

 

<%@ Assembly Name="<span style="font-weight:bold;">ASSEMBLYNAME</span>, Version=1.0.0.0, Culture=neutral, PublicKeyToken=<span style="font-weight:bold;">b1be248cde129fd5</span>" %>

<%@ Page Language="C#" AutoEventWireup="true"  Inherits="<span style="font-weight:bold;">NAMESPACE</span>._Default" MasterPageFile="~/_layouts/application.master" %>



<asp:Content ID="Content1" ContentPlaceHolderId="PlaceHolderMain" runat="server"><div>Title of this site: <asp:Label ID="LabelTitle" runat="server" Text="Label"></asp:Label></div></asp:Content><asp:Content ID="Content2" ContentPlaceHolderId="PlaceHolderPageTitleInTitleArea" runat="server">Test My ASP.NET Web Application

</asp:Content>

To download the sample page, here is the link:
http://cid-4bc94054914a6469.skydrive.live.com/self.aspx/Blog%20Code/home.aspx


Note: all your pages have to have 3 content controls that mimics the contentplaceholder that you have on your custom masterpage or sharepoint out of the box master page.

Tip: to get the public key token, just drag and drop your dll in GAC and right click on your assembly in your gac folder ( c:\windows\assembly) and you will get the public key token that you need to paste on all your pages.

7) To change the master page to your pages to the sharepoint master page, write the following method on your .cs file of your page:

 

protected override void OnPreInit(EventArgs e){base.OnPreInit(e);SPWeb Web = SPContext.Current.Web;this.MasterPageFile = Web.MasterUrl;}

8) One you are done, publish your website using publishing feature on your web application, right click on the web application and click on publish.

set the url of the web application to be under LAYOUTS folder in sharepoint.


9) Last, Deploy the web application dll file in GAC, you can create a feature for that, for development purposes, just drag and drop the webapplication.dll in your GAC under c:\windows\assembly folder.


10) Navigate to your test page and will see it works perfect, url for example :
http://SHAREPOINTSITE/_layouts/WEBSITEFOLDER/home.aspx

Hope this helps.

 
Sign Up to vote for this article
 
About Author
 
Mostafa Elzoghbi
Occupation-
Company-
Member Type -Junior
Location-United States
Joined date-07 Jun 2010
Home Page-http://moustafa-arafa.blogspot.com
Blog Page-http://moustafa-arafa.blogspot.com
MCSD,MCT,MCTS,C# MVP
 
 
Other popularSectionarticles
Comments
There is no comments for this articles.
Leave a Reply
Title:
Display Name:
Email:
(not display in page for the security purphase)
Website:
Message:
Please refresh your screen using Ctrl+F5
If you can't read this number refresh your screen
Please input the anti-spam code that you can read in the image.
^ Scroll to Top