SharePoint开发 - 自定义页面(错误页、登出页)

博客地址 http://blog.csdn.net/foxdave

本文叙述如何自定义SharePoint的固有页面,比较简单,用一句话说就是“做个页面,写一句代码。”

创建SharePoint空解决方案,添加Layouts映射文件夹,添加页面文件error.aspx和signout.aspx。

error.aspx

<%@ Assembly Name="$SharePoint.Project.AssemblyFullName$" %>
<%@ Import Namespace="Microsoft.SharePoint.ApplicationPages" %>
<%@ Register TagPrefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls"
    Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register TagPrefix="Utilities" Namespace="Microsoft.SharePoint.Utilities" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register TagPrefix="asp" Namespace="System.Web.UI" Assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" %>
<%@ Import Namespace="Microsoft.SharePoint" %>
<%@ Assembly Name="Microsoft.Web.CommandUI, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="error.aspx.cs" Inherits="CustomPages.error"
    DynamicMasterPageFile="~masterurl/default.master" %>

<asp:Content ID="PageHead" ContentPlaceHolderID="PlaceHolderAdditionalPageHead" runat="server">
</asp:Content>
<asp:Content ID="Main" ContentPlaceHolderID="PlaceHolderMain" runat="server">
    出现错误,请联系管理员
    <!--自定义错误页面,在此页面写代码-->
</asp:Content>
<asp:Content ID="PageTitle" ContentPlaceHolderID="PlaceHolderPageTitle" runat="server">
    应用程序页
</asp:Content>
<asp:Content ID="PageTitleInTitleArea" ContentPlaceHolderID="PlaceHolderPageTitleInTitleArea"
    runat="server">
    我的应用程序页
</asp:Content>
signout.aspx

<%@ Assembly Name="$SharePoint.Project.AssemblyFullName$" %>
<%@ Import Namespace="Microsoft.SharePoint.ApplicationPages" %>
<%@ Register TagPrefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls"
    Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register TagPrefix="Utilities" Namespace="Microsoft.SharePoint.Utilities" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register TagPrefix="asp" Namespace="System.Web.UI" Assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" %>
<%@ Import Namespace="Microsoft.SharePoint" %>
<%@ Assembly Name="Microsoft.Web.CommandUI, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="signout.aspx.cs" Inherits="CustomPages.signout"
    MasterPageFile="~/_layouts/simple.master" %>

<asp:Content ContentPlaceHolderID="PlaceHolderPageTitle" runat="server">
    <SharePoint:EncodedLiteral runat="server" Text="<%$Resources:wss,signout_pagetitle%>"
        EncodeMethod='HtmlEncode' />
</asp:Content>
<asp:Content ContentPlaceHolderID="PlaceHolderPageTitleInTitleArea" runat="server">
    <SharePoint:EncodedLiteral runat="server" Text="<%$Resources:wss,signout_pagetitle%>"
        EncodeMethod='HtmlEncode' />
</asp:Content>
<asp:Content ContentPlaceHolderID="PlaceHolderAdditionalPageHead" runat="server">
    <script type="text/javascript">
        function ULSd63() { var o = new Object; o.ULSTeamName = "Microsoft SharePoint Foundation"; o.ULSFileName = "SignOut.aspx"; return o; }
        function _spBodyOnLoad() {
            ULSd63: ;
            window.close();
        }
    </script>
</asp:Content>
<asp:Content ContentPlaceHolderID="PlaceHolderMain" runat="server">
    <asp:Label ID="lbPageDescription" Text="<%$Resources:wss,signout_pagedescription%>"
        runat="server" />
</asp:Content>
自定义页面的好处是可以处理一些自己实际中需要的操作。

然后添加feature,激活和取消激活事件

public override void FeatureActivated(SPFeatureReceiverProperties properties)
        {
            SPWebApplication webApp = properties.Feature.Parent as SPWebApplication;
            if (null != webApp)
            {
                webApp.UpdateMappedPage(SPWebApplication.SPCustomPage.Error, "/_layouts/SP_MIP/CustomPages/error.aspx");
                webApp.UpdateMappedPage(SPWebApplication.SPCustomPage.Signout, "/_layouts/SP_MIP/CustomPages/signout.aspx");
                webApp.Update(true);
            }
        }

        public override void FeatureDeactivating(SPFeatureReceiverProperties properties)
        {
            SPWebApplication webApp = properties.Feature.Parent as SPWebApplication;
            if (null != webApp)
            {
                webApp.UpdateMappedPage(SPWebApplication.SPCustomPage.Error, null);
                webApp.UpdateMappedPage(SPWebApplication.SPCustomPage.Signout, null);
                webApp.Update(true);
            }
        }
核心就一句话

webApp.UpdateMappedPage(SPWebApplication.SPCustomPage.Error,"/_layouts/SP_MIP/CustomPages/error.aspx");

有这些页面可以自定义




  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
自定义 SharePoint 登录页面的后台代码,需要进行以下步骤: 1. 创建一个新的 SharePoint 项目,并添加一个新的 Application Page。 2. 在 Application Page 中添加一个 ASP.NET 登录控件,以便用户可以输入其凭据。 3. 使用 SharePoint 对象模型或 CSOM(客户端对象模型)来验证用户凭据。 4. 如果凭据有效,则将用户重定向到 SharePoint 站点的默认页面。 以下是一个简单的示例代码,可以作为参考: ```c# using Microsoft.SharePoint; using Microsoft.SharePoint.WebControls; using System; using System.Web.UI.WebControls; namespace CustomLoginPage.Layouts.CustomLoginPage { public partial class Login : LayoutsPageBase { protected void Page_Load(object sender, EventArgs e) { // Check if the user is already authenticated if (SPContext.Current.Web.CurrentUser != null) { // Redirect to the default page SPUtility.Redirect(SPContext.Current.Web.Url, SPRedirectFlags.Default, HttpContext.Current); } } protected void LoginButton_Click(object sender, EventArgs e) { // Authenticate the user using SharePoint object model or CSOM bool isAuthenticated = AuthenticateUser(UsernameTextBox.Text, PasswordTextBox.Text); if (isAuthenticated) { // Redirect to the default page SPUtility.Redirect(SPContext.Current.Web.Url, SPRedirectFlags.Default, HttpContext.Current); } else { // Display an error message ErrorLabel.Text = "Invalid username or password"; } } private bool AuthenticateUser(string username, string password) { // TODO: Authenticate the user using SharePoint object model or CSOM // You can use the following code to authenticate the user using SharePoint object model: //using (SPSite site = new SPSite(SPContext.Current.Web.Url)) //{ // using (SPWeb web = site.OpenWeb()) // { // if (web.Site.WebApplication.UseClaimsAuthentication) // { // return SPClaimsUtility.AuthenticateFormsUser( // Context.Request.UrlReferrer, // username, // password); // } // else // { // return web.Authenticate(username, password); // } // } //} // Replace the above code with your own authentication logic return true; } } } ``` 请注意,此示例仅演示了如何在后台代码中验证用户凭据。要完全自定义 SharePoint 登录页面,您还需要编写自己的 HTML 和 CSS 代码,以及处理其他相关的逻辑。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值