有没有办法将错误处理程序HTTPModule放在web中的modules部分的开头。配置而不手动执行此操作?

我试过补充网络。配置方法是这样的:

  <add path="configuration/system.webServer/modules" id="{125A654F-9220-42F0-A97A-1746252468DE}">
    <add name="CustomErrorHandler" type="com.handlers.CustomErrorHandler, Assemblyname, Version=4.5.6.7, Culture=neutral, PublicKeyToken=3450345789" />
  </add>

问题是自定义错误处理程序必须放在标准处理程序之前。如果不这样做,sharepoint会处理异常本身并提供标准异常页面。

预期的:

 <modules runAllManagedModulesForAllRequests="true">
  <add name="CustomErrorHandler" type="com.handlers.CustomErrorHandler, Assemblyname, Version=4.5.6.7, Culture=neutral, PublicKeyToken=3450345789" />
  <remove name="FileAuthorization" />
  <remove name="Profile" />
  <remove name="WebDAVModule" />
  <remove name="Session" />
  <add name="SPRequestModule" preCondition="integratedMode" type="Microsoft.SharePoint.ApplicationRuntime.SPRequestModule, Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" />
  <add name="ScriptModule" preCondition="integratedMode" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
  <add name="SharePoint14Module" preCondition="integratedMode" />
  <add name="StateServiceModule" type="Microsoft.Office.Server.Administration.StateModule, Microsoft.Office.Server, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" />
  <add name="RSRedirectModule" type="Microsoft.ReportingServices.SharePoint.Soap.RSRedirectModule, RSSharePointSoapProxy, Version=10.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91" />
  <add name="PublishingHttpModule" type="Microsoft.SharePoint.Publishing.PublishingHttpModule, Microsoft.SharePoint.Publishing, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" />
</modules>

补充方法的结果:

<modules runAllManagedModulesForAllRequests="true">
  <remove name="FileAuthorization" />
  <remove name="Profile" />
  <remove name="WebDAVModule" />
  <remove name="Session" />
  <add name="SPRequestModule" preCondition="integratedMode" type="Microsoft.SharePoint.ApplicationRuntime.SPRequestModule, Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" />
  <add name="ScriptModule" preCondition="integratedMode" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
  <add name="SharePoint14Module" preCondition="integratedMode" />
  <add name="StateServiceModule" type="Microsoft.Office.Server.Administration.StateModule, Microsoft.Office.Server, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" />
  <add name="RSRedirectModule" type="Microsoft.ReportingServices.SharePoint.Soap.RSRedirectModule, RSSharePointSoapProxy, Version=10.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91" />
  <add name="PublishingHttpModule" type="Microsoft.SharePoint.Publishing.PublishingHttpModule, Microsoft.SharePoint.Publishing, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" />
  <add name="CustomErrorHandler" type="com.handlers.CustomErrorHandler, Assemblyname, Version=4.5.6.7, Culture=neutral, PublicKeyToken=3450345789" />
</modules>

就像这个线程所说的(ms Developer的confiremd)在使用SPWebConfigModification时没有办法控制节点的顺序:

http://social.technet.microsoft.com/Forums/en-US/sharepoint2010programming/thread/154a09de-d9fc-4622-a397-589a3c1a87e5/

添加web。手动配置条目是没有选择的.

真的没有别的办法了吗?

有帮助吗?

解决方案 2

最后,我最终以不同的方法为自定义错误页面结束。

因为不可能以编程方式控制Web.config中的元素顺序(这太糟糕了!)和手动编辑是没有选项,我以httpmodule和操纵web.config的方法。

相反,我写了一个Web应用程序范围特征接收器,如这里所述: http://todd-carter.com /post/2010/04/07/an-appected-error-has-occurred.aspx 设置应用程序的自定义错误页面(处理异常)。自定义错误页面有一个控件,它呈现用户的自定义消息,并记录异常。

另外,我将自定义404.html文件添加到映射的laylouts \ 1033文件夹中的解决方案中,并在同一特征接收器中注册了该文件的文件(请参阅下面的代码)。 404.html对.aspx文件进行重定向。 ASPX有一个控制,使内容赋予国际化的内容。您还可以设置404错误的静态HTML。重定向的原因是国际化。

与.html文件和非IE浏览器的一个额外的陷阱是给我这里描述的问题(因为我复制了一个起点的标准sp 404.html):

http://andreasglaser.net/post/2009/03/15/ sharepoint-and-custom-404- page-not-found-dand-firefox。 aspx

代码进入:

private const string CustomErrorPage = "/_layouts/CustomError.aspx";

public override void FeatureActivated(SPFeatureReceiverProperties properties)
{
  SPWebApplication webApp = properties.Feature.Parent as SPWebApplication;

  if (webApp != null)
  {
    if (!webApp.UpdateMappedPage(SPWebApplication.SPCustomPage.Error, CustomErrorPage))
    {
      throw new ApplicationException("Cannot create the new error page mapping.");
    }
  }

  webApp.FileNotFoundPage = "Custom404.html";
  webApp.Update(true);
}

public override void FeatureDeactivating(SPFeatureReceiverProperties properties)
{
  SPWebApplication webApp = properties.Feature.Parent as SPWebApplication;

  if (!webApp.UpdateMappedPage(SPWebApplication.SPCustomPage.Error, null))
  {
    throw new ApplicationException("Cannot reset the default error page mapping.");
  }
  webApp.FileNotFoundPage = String.Empty;
  webApp.Update(true);
}
.

其他提示

如果它不能按预期工作,那么我会建议你使用 Xpath与SPWebModifications一起 来定义顺序。

更新资料

我只是将我的解决方案与XPath解决方案一起测试出来,并且它的行为不像预期的那样。似乎有 没门! 控制条目的顺序。感谢Per的投入!

更新2

你能试试用吗? HttpApplication 而不是 HttpContext 因为 HttpApplication 定义一个应用程序对象中所有应用程序对象通用的方法、属性和事件ASP.NET 申请。 查看更多

使用方法

 HttpContext context = ((HttpApplication)sender).Context;
许可以下: CC-BY-SA归因
scroll top