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 ...
随机推荐
- javascript中的Array对象 —— 数组的合并、转换、迭代、排序、堆栈
Array 是javascript中经常用到的数据类型.javascript 的数组其他语言中数组的最大的区别是其每个数组项都可以保存任何类型的数据.本文主要讨论javascript中数组的声明.转换 ...
- 火焰图分析openresty性能瓶颈
注:本文操作基于CentOS 系统 准备工作 用wget从https://sourceware.org/systemtap/ftp/releases/下载最新版的systemtap.tar.gz压缩包 ...
- 【调侃】IOC前世今生
前些天,参与了公司内部小组的一次技术交流,主要是针对<IOC与AOP>,本着学而时习之的态度及积极分享的精神,我就结合一个小故事来初浅地剖析一下我眼中的“IOC前世今生”,以方便初学者能更 ...
- 使用Visual Studio SDK制作GLSL词法着色插件
使用Visual Studio SDK制作GLSL词法着色插件 我们在Visual Studio上开发OpenGL ES项目时,避免不了写Shader.这时在vs里直接编辑shader就会显得很方便. ...
- HTML5新特性有哪些,你都知道吗
一.画布(Canvas) 画布是网页中的一块区域,可所以用JavaScript在上面绘图.下面我们来创建一个画布并在上面绘制一个坦克(后面将用HTML5做一个坦克大战游戏),代码如下: <!DO ...
- Kooboo CMS技术文档之三:切换数据存储方式
切换数据存储方式包括以下几种: 将文本内容存储在SqlServer.MySQL.MongoDB等数据库中 将站点配置信息存储在数据库中 将后台用户信息存储在数据库中 将会员信息存储在数据库中 将图片. ...
- 【HTML】Html页面跳转的5种方式
目录结构: // contents structure [-] html实现 javascript方式实现 结合了倒数的javascript实现(IE) 解决Firefox不支持innerText的问 ...
- windows下mongodb配置
打开cmd(windows键+r输入cmd)命令行,进入D:\mongodb\bin目录(如图先输入d:进入d盘然后输入cd d:\mongodb\bin), 输入如下的命令启动mongodb服务: ...
- a标签绝对定位,点击区域被图片遮挡(IE下)
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- linux下mono的安装与卸载
我很遗憾的告诉你,这里没有安装,为什么标题里加入安装俩字呢,因为如果不加的话你会搜到这篇文章吗?哈哈!别气馁,这里会给你些安装的tips! 源码安装,git安装:建议安装路径如下,至于为什么,我也讲不 ...