正确的修改自定义母版页方式

  网上大部分文章都是用sharepoint designer 去修改母版页,这种方式虽然能达到目的,但你的母版页存在数据库(spd设计的母版页没有保存在服务器磁盘),每次都要用spd去打开修改,不便于维护迁移,如果交接工作下一个接手人不知道这个,那就更加麻烦了。

  正确的方式是在VS中新建一个母版页,修改前端,然后在VS的sharepoint项目的Feature使用事件去修改。

  意思是每当这个Feature激活时,我们就将该SPWeb的母版页修改成我们自定义的母版页。

  代码如下:

  

if (pageNo.Equals("1"))
             {
                 page.MasterPageFile = "~masterurl/custom.master";
                 if (SPContext.Current != null)
                 {
                     SPContext.Current.Web.CustomMasterUrl = 
				"/_catalogs/masterpage/custom1.master";
                 }
             }
             else if (pageNo.Equals("2"))
             {
                 page.MasterPageFile = "~masterurl/custom.master";
                 if (SPContext.Current != null)
                 {
                     SPContext.Current.Web.CustomMasterUrl = 
				"/_catalogs/masterpage/custom2.master";
                 }
             }
             else
             {
                 page.MasterPageFile = "~masterurl/default.master";
                 if (SPContext.Current != null)
                 {
                     SPContext.Current.Web.MasterUrl = 
				"/_catalogs/masterpage/default.master";
                 }
             }

  这里需要注意的是Customer母版页和Master母版页。

  Customer母版页供用户查看,Master母版页是系统管理员进入系统页面使用的母版页。

 

  

 

转载于:https://www.cnblogs.com/olay/p/6800839.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值