在SharePoint2010中用out-of-box的方式自定制Application Pages(AccessDenied,Confirmation,Error,Login,RequestAccess,Signout,WebDeleted)

在实际项目中需要对SharePoint2010中的AccessDenied页面进行自定制,于是乎上网搜索相关内容,经实际操作此方法可行,便以此文记录。

在SharePoint2010中,由于security的问题,master pages是不能够应用到application pages(AccessDenied,Confirmation,Error,Login,RequestAccess,Signout,WebDeleted)中的;所以我们将不得不创建一个新的application page,并且运行power shell命令 Set-SPCustomLayoutsPage来达到我们预期的效果。

在WSS3.0和MOSS2007中由于没有out-of-box的方式去修改SharePointRoot文件,因此想要自定制这样的Access Denied页面或者Sign Out页面是一件令人头疼的事情。

不过在SPF2010和SPS2010中我们可以用PowerShell的命令去将application page指定到我们自定义的页面中(即:用out-of-box的方式自定制application page),类似于url的重定向。

此处PowerShell命令的基本的格式为(即:重新设置application page所指定的url):

Set-SPCustomLayoutsPage -Identity "{页面的类型}" -RelativePath “{自定制页面的url}” -WebApplication “{当前webapp的url}”

这里的页面类型分别为:AccessDenied,Confirmation,Error,Login,RequestAccess,Signout,WebDeleted。

当然了这些类型是一组枚举类型我们可以用数字0,1,2......等对应代替,具体可以看:http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.administration.spwebapplication.spcustompage.aspx

例如如下代码实例:

    Set-SPCustomLayoutsPage -Identity "AccessDenied" -RelativePath "/_layouts/custompages/accessdenied.aspx" -WebApplication "http://server_name/mywebapp"

当用户去访问一个没有权限访问的页面时,会将页面重定向到我们自定义的accessdenied.aspx页面上,当然了由命令行可知这个页面放在了对应的SharePoint Server的.../14/TEMPLATE/LAYOUT/custompages 目录中。

-------------------------------------------------------------

Set-SPCustomLayoutsPage : http://technet.microsoft.com/en-us/library/ff607768.aspx

Get-SPCustomLayoutsPage : http://technet.microsoft.com/en-us/library/ff607821.aspx

原文地址:https://www.cnblogs.com/mingmingruyuedlut/p/3154402.html