繁体   English   中英

在sharepoint _layouts文件夹中创建自定义Webapp

[英]creating custom webapp in sharepoint _layouts folder

我第一次尝试在共享点Web服务器上创建自定义asp.net网站,我创建了以下Default.aspx

<%@ 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>

与以下Default.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 /时,出现“找不到文件”错误。 有什么我想念的东西或应该跳过的设置吗?

谢谢。

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

添加程序集

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

接下来,删除CodeFile属性,并将Inherits属性中的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甚至具有带导航项目模板的“应用程序页面”,可帮助您快速入门。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM