自定义Sharepoint应用程序中的页面继承

时间:2010-08-02 22:51:04

标签: c# asp.net sharepoint

我在sharepoint服务器上的_layouts / sandbox文件夹中有一个default.aspx。

它有以下代码:

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;
using Microsoft.SharePoint.WebControls;

using System.Web.Configuration;

namespace sandbox
{

    public partial class _Default : LayoutsAppPage
    {

        protected void Page_Load(object sender, EventArgs e)
        {
            SPWeb web = SPContext.Current.Web;
            LabelTitle.Text = web.Title;

            if (Page.IsPostBack == false)
            {
                //Label1.Text = "Fahrenheit to Celsius:";
            }
        }

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

            try
            {
                this.MasterPageFile = SPContext.Current.Web.MasterUrl;
            }
            catch
            {
            }
        }



    }

}

它应该继承LayoutsAppPage类,以便我可以使用它来在“沙盒”应用程序的所有页面中执行OnPreInit函数。这是LayoutsAppPage.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;
using Microsoft.SharePoint.WebControls;

using System.Web.Configuration;

namespace sandbox
{
    public class LayoutsAppPage : System.Web.UI.Page
    {
        protected override void OnPreInit(EventArgs e)
        {
            base.OnPreInit(e);

            try
            {
                this.MasterPageFile = SPContext.Current.Web.MasterUrl;
            }
            catch
            {
            }
        }
    }
}

运行页面时出现以下错误

  

c:\ Program Files \ Common   Files \ Microsoft Shared \ Web Server   扩展\ 12 \ TEMPLATE \ LAYOUTS \沙箱\ Default.aspx.cs(20):   错误CS0246:类型或命名空间   名称'LayoutsAppPage'不能   发现(你错过了使用   指令或汇编参考?)
  在   System.Web.Compilation.AssemblyBuilder.Compile()

我注意到在“公共部分类_Default:LayoutsAppPage”行中,LayoutsAppPage没有像基础类那样变成淡蓝色。如果该行是“public partial class _Default:System.Web.UI.Page”,则页面加载正常。也许我已经错误地声明了基页?

编辑:按要求 -

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="sandbox._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" %>

<%@ Register TagPrefix="wssuc" TagName="InputFormSection" Src="/_controltemplates/InputFormSection.ascx" %>
<%@ Register TagPrefix="wssuc" TagName="InputFormControl" Src="/_controltemplates/InputFormControl.ascx" %>
<%@ Register TagPrefix="wssuc" TagName="ButtonSection" Src="/_controltemplates/ButtonSection.ascx" %>
<%@ Register TagPrefix="wssuc" TagName="ToolBar" Src="/_controltemplates/ToolBar.ascx" %>
<%@ Register TagPrefix="wssuc" TagName="ToolBarButton" Src="/_controltemplates/ToolBarButton.ascx" %>

1 个答案:

答案 0 :(得分:0)

如果您的程序集已部署到GAC或使用公钥签名,那么您必须指定Page元素的inherits属性才能使用完整类型&amp;程序集名称如下:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="_Default.aspx.cs" 
Inherits="CustomAssemblyNamespace.sandbox._Default, CustomAssembly, Version=1.0.0.0, Culture=neutral, PublicKeyToken=1a01d56a735c19c1"  %>