2010-07-20 86 views
0

我试图首次创建SharePoint Web服务器上的自定义asp.net网站,我已经创建了下面的Default.aspx在SharePoint _layouts文件夹中创建自定义Web应用

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" MasterPageFile="~/_layouts/application.master" %> 
<%@ Assembly Name="Microsoft.SharePoint.ApplicationPages,Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %> 
<%@ Register Tagprefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %> 
<%@ Register Tagprefix="Utilities" Namespace="Microsoft.SharePoint.Utilities" Assembly="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %> 


<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 ASP.NET 2.0 Application 
</asp:Content> 

与下面的默认.aspx.cs

using System; 
using System.Configuration; 
using System.Data; 
using System.Linq; 
using System.Web; 
using System.Web.Security; 
using System.Web.UI; 
using System.Web.UI.HtmlControls; 
using System.Web.UI.WebControls; 
using System.Web.UI.WebControls.WebParts; 
using System.Xml.Linq; 

using Microsoft.SharePoint; 


public partial class _Default : System.Web.UI.Page 
{ 
    protected void Page_Load(object sender, EventArgs e) 
    { 
     SPWeb web = SPcontext.Current.Web; 
     LabelTitle.Text = web.Title; 
    } 

    protected override void OnPreInit(EventArgs e) 
    { 
     base.OnPreInit(e); 

     SPWeb web = SPContext.Current.Web; 

     String strUrl = web.ServerRelativeUrl + "/_catalogs/masterpage/default.aster"; 

     this.MasterPageFile = strUrl; 
    } 
} 

我也是在web.config中注释掉,而我包括Microsoft.SharePoint.dll的作为项目的引用。然后我删除了_layouts \ TestWebsite \

下的整个文件夹。但是,当进入http://server/_layouts/TestWebSite/时,出现'文件未找到'错误。有什么我失踪或我应该跳过的设置?

谢谢。

回答

0

您需要以不同的方式设置您的Page指令,并且不能使用将ASP.net页面添加到项目的常规方式。

添加您的装配

<%@ Assembly Name="Your.Four.Part.AssemblyName" %> 

然后拆掉的CodeFile属性,并与在汇编页面类的名称的继承属性替换default.aspx.cs。

你的页面指令看起来应该是这样的:

<%@ Page Language="C#" Inherits="NameSpace.ClassNameInCodeBehind" MasterPageFile="~/_layouts/application.master" %> 

如果你这样做“的背后在SharePoint代码”的搜索,你会发现很多文章像这样的:http://www.andrewconnell.com/blog/articles/UsingCodeBehindFilesInSharePointSites.aspx

它还有助于为此类项目获得WSPBuilder或STSDev。 STSDev甚至有一个带导航的应用程序页面项目模板,可以帮助您快速完成任务。

相关问题