本文主要介绍如何添加一个custom application page as site welcome page

1、首先创建一个sharepoint 2013 empty solution, add a custom application page(farm only)named MyHomePage.

2、自定义这个MyHomePage,显示所需信息,包括后台代码的编辑。

3、更改MyHomePage.aspx页面首页<%@ Assembly Name="$SharePoint.Project.AssemblyFullName$" %>为具体的assmebly info,例:

<%@ Assembly Name="MyHomePage, Version=1.0.0.0, Culture=neutral, PublicKeyToken=77a2aedaefb0d45b" %>

4、右键solution,添加一个module,named:HomePage, 替换module 下sample.txt为MyHomePage.aspx,同时修改里面的<%@ Page %>,

<%@ Page Language="C#" AutoEventWireup="true" Inherits="MyHomePage.Layouts.MyHomePage.MyHomePage" MasterPageFile="../_catalogs/masterpage/seattle.master" %>

指定具体的master file,不能DynamicMasterPageFile="~masterurl/default.master" ,同时去掉CodeBehind 标签,原因是copy这个页面没有后台。

NOTE:这里我们替换default.aspx中的DynamicMasterPageFile="~masterurl/default.mater"为MasterPageFile="../_catalogs/masterpage/seattle.master",其实这种方式不太好,原因在与sharepoint 2013本来支持动态更改         master文件,但是这里我们确把materpage固定了,所以客户是无法改变的。

SOLUTION:不指定DynamicMasterPageFileMasterPageFile,后台将default.aspx页继承的LayoutsPageBase更改为PublishingLayoutPage

HTML:

<%@ Page Language="C#" Inherits="EArchive.EArchiveHome" %>

C#:

 public partial class EArchiveHome : PublishingLayoutPage
{
protected void Page_Load(object sender, EventArgs e)
{ }
}

module code:

<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<Module Name="HomePage" Url="Pages" >
<File Path="HomePage\MyHome.aspx" Type="GhostableInLibrary" Url="MyHome.aspx" IgnoreIfAlreadyExists="FALSE" ReplaceContent="TRUE">
<Property Name="PublishingPageLayout" Value="~SiteCollection/_catalogs/masterpage/BlankWebPartPage.aspx, Blank Web Part page" />
</File>
</Module>
</Elements>

说明:Module name:HomePage,Url为Pages,Pages 是site 开启publishing feature之后sharepoint自动添加的一个page library,主要用于manage home or error SharePoint default pages.

重点需要说明的是<Property Name="PublishingPageLayout" Value="~SiteCollection/_catalogs/masterpage/BlankWebPartPage.aspx, Blank Web Part page" />这个property的作用是为这个MyHome.aspx页添加了一个PageLayout,

方便以后对这个homepage的添加与修改。

5、添加module的时候会默认在solution中add a feature,右键feature,添加feature EventReceiver,设置feature scope为site, 编辑FeatureActivated和FeatureDeactiving

FeatureActivated code:

 public override void FeatureActivated(SPFeatureReceiverProperties properties)
{
SPSecurity.RunWithElevatedPrivileges(() =>
{
SPSite site = properties.Feature.Parent as SPSite;
using (site)
{
SPWeb web = site.RootWeb;
web.AllowUnsafeUpdates = true;
if (PublishingWeb.IsPublishingWeb(web))
{
PublishingWeb pWeb = PublishingWeb.GetPublishingWeb(web);
SPFile file = web.GetFile(web.ServerRelativeUrl + "/Pages/MyHome.aspx");
pWeb.DefaultPage = file;
pWeb.Update();
}
else
{
web.RootFolder.WelcomePage = "Pages/MyHome.aspx";
web.RootFolder.Update();
web.Update();
}
web.AllowUnsafeUpdates = false;
}
});
}

注意:set welcome page的时候,需要check 当前的site是否开启了publishing feature,具体情况如上面代码所示。

FeatureDeactiving code:

 public override void FeatureDeactivating(SPFeatureReceiverProperties properties)
{
SPSecurity.RunWithElevatedPrivileges(() =>
{
SPSite site = properties.Feature.Parent as SPSite;
using (site)
{
SPWeb web = site.RootWeb;
web.AllowUnsafeUpdates = true;
if (PublishingWeb.IsPublishingWeb(web))
{
PublishingWeb pWeb = PublishingWeb.GetPublishingWeb(web);
SPFile file = web.GetFile(web.ServerRelativeUrl + "/Pages/Home.aspx");
pWeb.DefaultPage = file;
pWeb.Update();
}
else
{
web.RootFolder.WelcomePage = "Pages/Home.aspx";
web.RootFolder.Update();
web.Update();
}
web.AllowUnsafeUpdates = false;
}
});
}

注意:deactive feature需要将site homepage设置成default page。

6、OK,一个完整set SharePoint homePage 的应用completly。

补充:如果我们create a custom application page,这个页默认继承LayoutsPageBase,这个class我们通过反射会发现里面有check permission的逻辑验证,所以说只有site 的 viewpage或者read权限才可以访问这个custom page。

但是有些客户就是不想给我们任何权限,然后呢,还想能访问这个custom application page,怎么办呢?经过楼主不断的研究,发现了其中的奥妙,就在于页面后台代码继承的这个class:LayoutsPageBase,将这个class更改为Page,            那么任何权限的user就都可以访问这个custom application page。

SharePoint2013 Set a custom application page as site welcome page的更多相关文章

  1. Web Application和Web Site两个模板的比较

    Scenario Web Application Project Web Site Project 项目定义 跟 Visual Studio .NET 2003 类似,由于项目文件的存在,只有被项目文 ...

  2. 2016/05/17 thinkphp3.2.2 分页的使用:①在Home下设置Publics文件夹或在thinkPHP下library的vender 把page.class.php 考贝进入 ②通过new 实例化方式调用 $page=new \Home\Publics\Page($total,3);

    注意分页的方法有两种:一种是thinkphp3.2 自带的   另一种是之前新闻页用过的     显示效果稍有差别 显示效果: 细节问题: ①搜索页面  要加session判断   和  分页 ②修改 ...

  3. sharepoint 2010 页面添加footer方法 custom footer for sharepoint 2010 master page

    转:http://blog.csdn.net/chenxinxian/article/details/8720893 在sharepoint 2010的页面中,我们发现,没有页尾,如果我们需要给页面添 ...

  4. EBS增加客制应用CUX:Custom Application

    1. 创建数据库文件和帐号 [root@ebs12vis oracle]# su - oracle[oracle@ebs12vis ~]$ sqlplus / as sysdba SQL*Plus: ...

  5. Page.ClientScript.RegisterStartupScript 与 Page.ClientScript.RegisterClientScriptBlock 之间的区别

    Page.ClientScript.RegisterClientScriptBlock 在页面紧跟<form>之后,整个页面未完全加载完成. Page.ClientScript.Regis ...

  6. [转]Repeat Page Header on each Page for reports SSRS

    本文转自:https://stackoverflow.com/questions/3475144/i-want-to-repeat-page-header-on-each-page-for-repor ...

  7. Jquery easyui 教程

            Jquery easyui教程                 目  录 1基本拖放... 4 2构建购物车型拖放... 5 3创建课程表... 8 4菜单和按钮Menu and Bu ...

  8. Custom ASP.NET Application into SharePoint --整合ASP.NET应用程序到SharePoint

    转:http://www.devexpertise.com/2009/02/18/integrating-a-custom-aspnet-application-into-sharepoint-par ...

  9. What technical details should a programmer of a web application consider before making the site public?

    What things should a programmer implementing the technical details of a web application consider bef ...

随机推荐

  1. 十分钟介绍mobx与react

    原文地址:https://mobxjs.github.io/mobx/getting-started.html 写在前面:本人英语水平有限,主要是写给自己看的,若有哪位同学看到了有问题的地方,请为我指 ...

  2. TODO:搭建Laravel VueJS SemanticUI

    TODO:搭建Laravel VueJS SemanticUI Laravel是一套简洁.优雅的PHP开发框架(PHP Web Framework).可以让你从面条一样杂乱的代码中解脱出来:它可以帮你 ...

  3. ajax前后端数据交互简析

    前端-------->后端 方法:POST 将要传递给后台的数据在前端拼接成url字符串,通过request.send()传递给后台,后台php把得到的数据以索引数组的方式存储在$_POST中. ...

  4. 套用JQuery EasyUI列表显示数据、分页、查询

    声明,本博客从csdn搬到cnblogs博客园了,以前的csdn不再更新,朋友们可以到这儿来找我的文章,更多的文章会发表,谢谢关注! 有时候闲的无聊,看到extjs那么肥大,真想把自己的项目改了,最近 ...

  5. 【读书】PHP程序员要读的书目(不断完善中)

    本文地址 分享提纲: 1. PHP 2. Linux 3. Apache/Nginx 4. Mysql 5.设计模式/架构 6. 缓存并发 7. 其他语言 8. 代码基础 9. 大前端 10. 管理生 ...

  6. iOS从零开始学习直播之2.采集

      直播的采集由采集的设备(摄像头.话筒)不同分为视频采集和音频采集,本篇文章会分别介绍. 1.采集步骤   1.创建捕捉会话(AVCaptureSession),iOS调用相机和话筒之前都需要创建捕 ...

  7. 命名sql数据集

    所谓的命名sql其实也就是数据库里的sql语句,普元EOS里做了一定的封装,以方便在程序中的使用. 命名SQL的基本元素包括: 1. <parameterMap> parameterMap ...

  8. win10电脑优化

    Windows10必做的优化 --道心 关闭服务 右键点击"此电脑",选择"管理",进入"计算机管理"窗口. 在左侧的菜单选择"服 ...

  9. windows系统路径环境变量

    当前系统盘符%systemdrive%或%HOMEDRIVE%C:\ 当前系统目录%systemroot%或%Windir%C:\WINDOWS 当前用户文件夹%UserProfile%或%HOMEP ...

  10. date命令

    GNU的date提供+%s(小写s), 能打印出自1970-01-01 00:00:00到当前时间的秒数. 这可能大家都不陌生,但有两点需要注意: 1. %s存在于GNU扩展版本.像在solaris等 ...