SharePoint2013 Set a custom application page as site welcome page
本文主要介绍如何添加一个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:不指定DynamicMasterPageFile及MasterPageFile,后台将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的更多相关文章
- Web Application和Web Site两个模板的比较
Scenario Web Application Project Web Site Project 项目定义 跟 Visual Studio .NET 2003 类似,由于项目文件的存在,只有被项目文 ...
- 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判断 和 分页 ②修改 ...
- sharepoint 2010 页面添加footer方法 custom footer for sharepoint 2010 master page
转:http://blog.csdn.net/chenxinxian/article/details/8720893 在sharepoint 2010的页面中,我们发现,没有页尾,如果我们需要给页面添 ...
- EBS增加客制应用CUX:Custom Application
1. 创建数据库文件和帐号 [root@ebs12vis oracle]# su - oracle[oracle@ebs12vis ~]$ sqlplus / as sysdba SQL*Plus: ...
- Page.ClientScript.RegisterStartupScript 与 Page.ClientScript.RegisterClientScriptBlock 之间的区别
Page.ClientScript.RegisterClientScriptBlock 在页面紧跟<form>之后,整个页面未完全加载完成. Page.ClientScript.Regis ...
- [转]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 ...
- Jquery easyui 教程
Jquery easyui教程 目 录 1基本拖放... 4 2构建购物车型拖放... 5 3创建课程表... 8 4菜单和按钮Menu and Bu ...
- Custom ASP.NET Application into SharePoint --整合ASP.NET应用程序到SharePoint
转:http://www.devexpertise.com/2009/02/18/integrating-a-custom-aspnet-application-into-sharepoint-par ...
- 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 ...
随机推荐
- Angular杂谈系列1-如何在Angular2中使用jQuery及其插件
jQuery,让我们对dom的操作更加便捷.由于其易用性和可扩展性,jQuer也迅速风靡全球,各种插件也是目不暇接. 我相信很多人并不能直接远离jQuery去做前端,因为它太好用了,我们以前做的东西大 ...
- java基础_集合List与Set接口
List接口继承了Collection的方法 当然也有自己特有的方法向指定位置添加元素 add(索引,添加的元素); 移除指定索引的元素 remove(索引) 修改指定索引的元素 set ...
- jQuery学习之路(8)- 表单验证插件-Validation
▓▓▓▓▓▓ 大致介绍 jQuery Validate 插件为表单提供了强大的验证功能,让客户端表单验证变得更简单,同时提供了大量的定制选项,满足应用程序各种需求.该插件捆绑了一套有用的验证方法,包括 ...
- iOS逆向工程之KeyChain与Snoop-it
今天博客的主题是Keychain, 在本篇博客中会通过一个登陆的Demo将用户名密码存入到KeyChain中,并且查看一下KeyChain中存的是什么东西,把这些内容给导出来.当然本篇博客的重点不是如 ...
- # PHP - 使用PHPMailer发邮件
PHPMailer支持多种邮件发送方式,使用起来非常简单 1.下载PHPMailer https://github.com/PHPMailer/PHPMailer,下载完成加压后, 把下边的两个文件复 ...
- 【夯实Nginx基础】Nginx工作原理和优化、漏洞
本文地址 原文地址 本文提纲: 1. Nginx的模块与工作原理 2. Nginx的进程模型 3 . NginxFastCGI运行原理 3.1 什么是 FastCGI ...
- Linux服务器安全配置
众所周知,网络安全是一个非常重要的课题,而服务器是网络安全中最关键的环节.Linux被认为是一个比较安全的Internet服务器,作为一种开放源代码操作系统,一旦Linux系统中发现有安全漏洞,Int ...
- css 填坑常用代码分享
以下是常用的代码收集,没有任何技术含量,只是填坑的积累.转载请注明出处,谢谢. 因为提交比较麻烦,后来转置github:https://github.com/jsfront/src/blob/mast ...
- 《徐徐道来话Java》:PriorityQueue和最小堆
在讲解PriorityQueue之前,需要先熟悉一个有序数据结构:最小堆. 最小堆是一种经过排序的完全二叉树,其中任一非终端节点数值均不大于其左孩子和右孩子节点的值. 可以得出结论,如果一棵二叉树满足 ...
- css 垂直水平居中总结
一.前言: 垂直居中有很多方式,我们要做的不是写出完美代码,而是在合适的情况下根据需求选择合适方式. 主要方式: line-height 绝对定位 表格 display:table-cell 主要需求 ...