MOSS / Sharepoint 2007 Custom Error Page and Access denied Page
2009-12-17 15:22
501 查看
In case if you are interested in creating your own custom error page and custom access denied page instead of the out of the box MOSS / Sharepoint error page (generally the requirements in Publishing internet site). You can use the following HTTPModule (this is just a sample, you can change it to suit your requirements):
Note to have following Web.config Entries:
Following entries in the <appsettings> section in the web.config file:
Following entry is for a custom error page to be displayed for anonymous users, the key should be in the format: “CustomAnonCustErrPG-SiteCollectionURL” as shown below:
<add key="CustomAnonCustErrPG-http://xyz.com" value="/Pages/default.aspx" />
Following entry is for a custom error page to be displayed for authenticated users, the key should be in the format: “CustomAuthCustErrPG-SiteCollectionURL” as shown below:
<add key="CustomAuthCustErrPG-http:// xyz.com " value="/Pages/default.aspx" />
Following entry is for a custom error page to be displayed for access denied errors, the key should be in the format: “CustomCustAcsDndPG -SiteCollectionURL” as shown below:
<add key="CustomCustAcsDndPG-http://xyz.com" value="/_layouts/XYZ/CustomErrPg.aspx " />
Create an entry on all the WFEs web-application specific web.config in the HTTPModules section, as follows just below the <HTTPModule> tag This should be the first entry in the HTTPModules section:
<add name="XYZExceptionHandler" type="XYZ.Sharepoint.HTTPModule.CustomErrorPages.CustomErrors, XYZ.Sharepoint.HTTPModule.CustomErrorPages, Version=1.0.0.0, Culture=neutral, PublicKeyToken=PUBLICKEYGUID" />
NOTE: Add your own Public key for PublicKeyToken per your snk used, replace the PUBLICKEYGUID with your own snk value
转载:http://blogs.msdn.com/ketaanhs/archive/2009/03/16/moss-sharepoint-2007-custom-error-page-and-access-denied-page.aspx
Note to have following Web.config Entries:
Following entries in the <appsettings> section in the web.config file:
Following entry is for a custom error page to be displayed for anonymous users, the key should be in the format: “CustomAnonCustErrPG-SiteCollectionURL” as shown below:
<add key="CustomAnonCustErrPG-http://xyz.com" value="/Pages/default.aspx" />
Following entry is for a custom error page to be displayed for authenticated users, the key should be in the format: “CustomAuthCustErrPG-SiteCollectionURL” as shown below:
<add key="CustomAuthCustErrPG-http:// xyz.com " value="/Pages/default.aspx" />
Following entry is for a custom error page to be displayed for access denied errors, the key should be in the format: “CustomCustAcsDndPG -SiteCollectionURL” as shown below:
<add key="CustomCustAcsDndPG-http://xyz.com" value="/_layouts/XYZ/CustomErrPg.aspx " />
Create an entry on all the WFEs web-application specific web.config in the HTTPModules section, as follows just below the <HTTPModule> tag This should be the first entry in the HTTPModules section:
<add name="XYZExceptionHandler" type="XYZ.Sharepoint.HTTPModule.CustomErrorPages.CustomErrors, XYZ.Sharepoint.HTTPModule.CustomErrorPages, Version=1.0.0.0, Culture=neutral, PublicKeyToken=PUBLICKEYGUID" />
NOTE: Add your own Public key for PublicKeyToken per your snk used, replace the PUBLICKEYGUID with your own snk value
// This is a HTTPModule used for redirecting the user to Home or Home Anon site depending on whether // s/he is authenticated or anonymous. // // The module checks if the url is accessdenied.aspx and redirects the user to proper url. //////////////////////////////////////////////////////////////////////////////////////////////// using System; using System.Web; using Microsoft.Practices.EnterpriseLibrary.ExceptionHandling; using System.Configuration; using Microsoft.SharePoint; namespace XYZ.Sharepoint.HTTPModule.CustomErrorPages { public class CustomErrors : IHttpModule { #region -- Private fields -- private static AppSettingsReader m_Reader = new AppSettingsReader(); private static string m_SiteCollAnonCustomErrPG = "CustomAnonCustErrPG"; private static string m_SiteCollAuthCustomErrPG = "CustomAuthCustErrPG"; private static string m_SiteCollCustAcsDndPG = "CustomCustAcsDndPG"; #endregion public void Init(HttpApplication context) { //Attaching event handlers for access denied and error respectively //context.BeginRequest += new EventHandler(context_AcessDenied); context.EndRequest += new EventHandler(context_AcessDenied); context.Error += new EventHandler(context_Error); } void context_AcessDenied(object sender, EventArgs e) { try { HttpApplication httpApp = sender as HttpApplication; HttpContext context = httpApp.Context; string httpUrl = context.Request.Url.ToString(); string strCustomAcssDndURL = string.Empty; string strSiteURL = string.Empty; if (httpUrl.ToLower().Contains("/_layouts/accessdenied.aspx")) { SPSecurity.RunWithElevatedPrivileges(delegate() { using (SPSite site = new SPSite(httpUrl)) { strSiteURL = site.Url; } }); HttpContext.Current.Server.ClearError(); HttpContext.Current.Response.Clear(); strCustomAcssDndURL = getAppSettingsValue(m_SiteCollCustAcsDndPG + "-" + strSiteURL); HttpContext.Current.Response.Redirect(strCustomAcssDndURL, false); } } catch (Exception ex) { //Do your exception handling } } void context_Error(object sender, EventArgs e) { try { string strURL = string.Empty; string strSiteURL = SPContext.Current.Site.Url; Exception[] unhandledExceptions = HttpContext.Current.AllErrors; //logging all the exceptions thru the Exception policy file foreach (Exception ex in unhandledExceptions) { //Do your exception handling } HttpContext.Current.Server.ClearError(); HttpContext.Current.Response.Clear();
if (HttpContext.Current.User.Identity.IsAuthenticated) { strURL = getAppSettingsValue(m_SiteCollAuthCustomErrPG + "-" + strSiteURL); HttpContext.Current.Response.Redirect(strURL, false); } else { strURL = getAppSettingsValue(m_SiteCollAnonCustomErrPG + "-" + strSiteURL); HttpContext.Current.Response.Redirect(strURL, false); } } catch (Exception ex) { //Do your exception handling } } public void Dispose() {
} //Method used to read Appsettings value from web.config for the webapplication private static string getAppSettingsValue(string sKey) { string sValue = null; try { sValue = m_Reader.GetValue(sKey, typeof(string)) as string; } catch (Exception ex) { //Do your exception handling } return sValue; }
} }
转载:http://blogs.msdn.com/ketaanhs/archive/2009/03/16/moss-sharepoint-2007-custom-error-page-and-access-denied-page.aspx
相关文章推荐
- How to create your own custom 404 error page and handle redirect in SharePoint 2007 (MOSS)?
- 转:How to create your own custom 404 error page and handle redirect in SharePoint 2007 (MOSS)?
- How to create your own custom 404 error page and handle redirect in SharePoint
- Code Access Security and SharePoint 2007 Web Parts
- ({i:0#.w|nt authority\iusr})Sharepoint impersonates the IUSR account and is denied access to resources
- Disabling Mobile Web Page Access in SharePoint Server 2010 and SharePoint Foundation 2010
- Office and SharePoint 2007 User's Guide: Integrating SharePoint with Excel, Outlook, Access and Word
- Setup and Install SharePoint 2007 Server (MOSS) on Virtual PC
- Starting SharePoint designer workflows and "Access Denied"
- Access denied error by access to a txt file on the sharepoint server
- Error message when you try to modify or to delete an alternate access mapping in Windows SharePoint Services 3.0: "An update conflict has occurred, and you must re-try this action"
- Creating a Custom SharePoint 2007 List Definition
- MOSS SharePoint 2007 SSP migration to SharePoint 2010
- Openning SharePoint - 80 website gives HTTP 404 Error, The webpage cannot be found ! on SharePoint 2013
- SharePoint 2007 系列(12) SharePoint Master Page
- 翻译(一)SharePoint 2007管理入门:Windows SharePoint Service 3.0 and Microsoft Office SharePoint Server 2007
- Microsoft SharePoint 2007 Technologies: Planning, Design and Implementation
- Creating a Custom Login Page for SharePoint 2010
- MOSS 2007 模板部署Sharepoint Services Administration没有启动问题
- Deploying a custom master page in SharePoint 2010