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 ...
随机推荐
- UWP 律师查询 MVVM
APP简介 律师查询是基于聚合数据的律师查询接口做的,这个接口目前处于停用状态,但是,由于我是之前申请的,所以,还可以用,应该是无法再申请了. 效果图 开发 一.HttpHelper 既然是请求接口的 ...
- C++中的时间函数
C++获取时间函数众多,何时该用什么函数,拿到的是什么时间?该怎么用?很多人都会混淆. 本文是本人经历了几款游戏客户端和服务器开发后,对游戏中时间获取的一点总结. 最早学习游戏客户端时,为了获取最精确 ...
- Paypal开发中遇到请求被中止: 未能创建 SSL/TLS 安全通道及解决方案
最近在基于ASP.NET上开发了Paypal支付平台,在ASP.NET开发的过程中没有遇到这个问题,但是引用到MVC开发模式中的时候就出现了"未能创建 SSL/TLS 安全通道及解决方案&q ...
- 计算机程序的思维逻辑 (60) - 随机读写文件及其应用 - 实现一个简单的KV数据库
57节介绍了字节流, 58节介绍了字符流,它们都是以流的方式读写文件,流的方式有几个限制: 要么读,要么写,不能同时读和写 不能随机读写,只能从头读到尾,且不能重复读,虽然通过缓冲可以实现部分重读,但 ...
- Go web开发初探
2017年的第一篇博客,也是第一次写博客,写的不好,请各位见谅. 本人之前一直学习java.java web,最近开始学习Go语言,所以也想了解一下Go语言中web的开发方式以及运行机制. 在< ...
- Android SDK 在线更新镜像服务器资源
本文转自:http://blog.kuoruan.com/24.html.感谢原作者. 什么是Android SDK SDK:(software development kit)软件开发工具包.被软件 ...
- 【夯实PHP基础】UML序列图总结
原文地址 序列图主要用于展示对象之间交互的顺序. 序列图将交互关系表示为一个二维图.纵向是时间轴,时间沿竖线向下延伸.横向轴代表了在协作中各独立对象的类元角色.类元角色用生命线表示.当对象存在时,角色 ...
- ubuntu14 安装及卸载vmware
原帖http://blog.sina.com.cn/s/blog_73dac6b50101gp4f.html 适用于ubuntu14和vmware player 12.5
- CYQ.Data V5 从入门到放弃ORM系列:教程 - MProc类使用
MProc介绍 MProc:是一个用于执行SQL或存储过程的数据库操作类,它轻量高性能地类似于Dapper. MProc:它出现的场景很少,因为MAction自身就能处理掉90%-100%的数据操作( ...
- 为Xamarin更好的开发而改写的库
欢迎大家加入以下开源社区 Xamarin-Cn:https://github.com/Xamarin-Cn Mvvmcross-Cn:https://github.com/Mvvmcross-Cn ...