Deploying ASP.NET in SharePoint 2007

I’ve been attempting to deploy a SharePoint Web Application and struggled to get going, until someone from the  UK SharePoint Users Group pointed out this resource from MSDN: http://msdn.microsoft.com/en-us/library/cc297200.aspx

Unfortunately that article didn’t work for me. But I stuck with it, and here is my take, hopefully will work for others.

Lets start out with some common ground – I’m using MS Visual Studio 2008, and targetting SharePoint 2007.

  1. Click File -> New Web Site, select File System and enter an appropriate path. (I’m using C# btw, by VB will be fine).
  2. Upon clicking OK a standard website will open. Keep things really simple to start with, type in ‘Hello World’ and then save the website. The code should look like follows:

    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">

     

    <head runat="server">
    <title></title>
    </head>
    <body>
    <form id="form1" runat="server">
    <div>
    Hello World
    </div>
    </form>
    </body>
    </html>
  3. Comment out the
    <!-- <authentication mode="Windows"/> -->

    line in the web.config. Please remember to do this, otherwise your SharePoint IIS may be taken down for a couple of minutes. The line should appear around Line 27 for those building in .NET 2.0 Framework, or around Line 52 for those building with .NET 3.5.

  4. On the SharePoint server, browse to ‘c:\program files\common files\microsoft shared\web server extensions\12\template\layouts’ and within the layouts directory create a new directory (something along the lines of your company name would be good).
  5. Copy the website files (Note: No need to build or compile, just copy them. Make sure you’ve saved the changes though) from your development machine to the SharePoint server, into the newly created directory under layouts.
  6. On a remote machine, fire up a browser and navigate to your SharePoint website (e.g. https://share.company.org.uk) and append ‘/_layouts/<NameOfDirectory>/Default.aspx’. At this stage you should get a very basic HelloWorld page appear.
  7. So at this stage we now know that we’ve managed to deploy a very basic site to SharePoint, lets try and get into styling it via a default Master Page.
  8. In the Default.aspx, alter the first line from:
    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

    to

    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" MasterPageFile="~/_layouts/application.master" %>
  9. Delete all the other lines from Default.aspx (so you should just have the one line that we previously edited). Now insert the following lines:
    <asp:Content ID="Content1" ContentPlaceHolderID="PlaceHolderPageTitleInTitleArea" runat="server">
    
    <asp:Label ID="lblTest" runat="server" Text="Hello World Title" />
    
    </asp:Content>
    
    <asp:Content ID="Content2" ContentPlaceHolderID="PlaceHolderMain" runat="server">
    
    Hello World
    
    </asp:Content>
  10. Again, copy make sure you save these files. (No need to build or compile the site).
  11. On the SharePoint server, overwrite the website previously copied (in the layouts/<TestDirectory>). On a remote machine, browse to the website again. You should get something like this:SharePoint ScreenShot

It is worth noting that I’ve just picked out the 2 Content Areas I need. Look at the Master Page on the server for all the possible content area combinations.

At this point, I’ll refer the reader back to the original MSDN article. This was sufficient for my end goal.

Hope this helps someone.

Advertisements

17 thoughts on “Deploying ASP.NET in SharePoint 2007

  1. Found this post helpful, But it’s a bit weird to me why it didn’t work in first place as the MSDN article described.

  2. This works fine. And, It uses SP Context as well. Anyone know how to enable AD Authentication for Intranet uses. And, Form Based Authentication when it accessed from extra net using ‘Extend the Website’ with different zone.

  3. Thanks for the post. It was extremely helpful. I do have a question. Is it possible to call the sharepoint web services within the custom asp page?
    I’ve tried building a test page to have a dropdown list to show the groups on the site but I always get a “Unknown Error” error message. The site works outside the sharepoint Environment.
    Thank you

  4. Thank you very much!
    The MSDN article is not explicit enough (assumes too much) and tries to handle it all @ once… (a common problem from Microsoft provided examples…).

    I would have quit/gone on to a different problem (not programming related) had you not provided this.

  5. How do we get the user contect in case the ssp is authenticated by LDAP I want the embedded web site to behave dynamically based on the context of the user in the SSP

    Please suggest

  6. Could u please let me know the same Deploying Procedure will apply to ASP.NET MVC in SharePoint 2007

    -Praveen Kumar

    • Hi Praveen,

      I’m afraid I’ve no longer got access to SharePoint having changed jobs, so I’m not able to help. Hopefully someone else may be able help.

      Cheers,
      Greg

  7. I tried the steps above – But even the simple Hello World does not appear. It just gives me a blank page. Any idea what could be wrong?

  8. the basic page worked..but after adding content parts
    Unknown Error is caused

    I assume the first line is

    Not sure why the article is not displaying complete code.

    • Hi John,

      I’m afraid I no longer develop in SharePoint, so can’t help out in this regard. Hopefully someone else may point you in the right direction.

      Cheers,
      Greg

      • OK..But how about SP Designer….??
        I need to Edit v4.master as I am adding few other table like structures and I am navigating to other site pages..

        Thanks,

      • Hi John,

        I really have no involvement at all in any aspect of SharePoint these days – my current employer doesn’t use SharePoint, and thus the opportunity no longer exists.

        Cheers,
        Greg

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s