Web.config의 모듈 섹션의 시작 부분에 사용자 지정 오류 처리기를 추가하십시오 (수동으로).
-
09-12-2019 - |
문제
이 작업을 수동으로 수행하지 않고도 Web.config의 모듈 섹션의 시작 부분에 오류 처리기 httpmodule을 넣는 방법이 있습니까?
다음과 같은 보충 Web.config 접근 방식을 시도했습니다.
<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 개발자가 Confiremd) spwebconfigModification으로 작업 할 때 노드의 순서를 제어 할 수있는 방법이 없습니다.
web.config 항목을 수동으로 추가하는 것은 옵션이 아닙니다.
다른 방법이 없습니다.
해결책 2
마침내 나는 사용자 정의 오류 페이지에 대해 다른 접근 방식으로 끝났습니다.
프로그래밍 방식으로 Web.config에서 요소의 순서를 제어 할 수 없으므로 수동으로 수동으로 편집하는 것은 HttpModule 및 Web.config를 조작하는 방법을 포기하지 않습니다. 대신 여기에 설명 된 것처럼 웹 응용 프로그램 범위가있는 기능 수신기를 썼습니다. http://todd-carter.com. /post/2010/04/07/An-Expected-Error-has-occurred.aspx 응용 프로그램의 사용자 지정 오류 페이지를 설정합니다 (예외 처리). 사용자 정의 오류 페이지에는 사용자의 사용자 지정 메시지를 렌더링하고 예외를 기록하는 컨트롤이 있습니다.
또한 맵핑 된 레이아웃 \ 1033 폴더의 솔루션에 사용자 정의 404.html 파일을 추가하고 동일한 기능 수신자의 응용 프로그램에 대한 파일을 등록했습니다 (아래 코드 참조). 404.html은 .aspx 파일로 리디렉션됩니다. ASPX는 국제화 된 콘텐츠를 렌더링하는 컨트롤을 갖추고 있습니다. 404 오류에 대해 정적 HTML을 설정할 수도 있습니다. 리디렉션의 이유는 국제화였습니다.
하나의 추가로 .html 파일과 비 파일로 브라우저가 아닌 브라우저가 여기에 설명 된 문제가되었습니다 (시작점에 대해 표준 SP 404.html을 복사했기 때문에) :
코드가 여기에 간다 :
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를 사용하는 것이 좋습니다.주문을 정의하기 위해 spwebmodification 와 함께
업데이트
방금 XPath 솔루션과 함께 해결책을 테스트했으며 예상대로 작동하지 않습니다.엔트리의 순서를 제어하는 가없는 것 같습니다.그의 입력에 대한 감사합니다!
업데이트 2
HttpApplication
가 ASP.NET 응용 프로그램의 모든 응용 프로그램 개체에 공통된 메소드, 속성 및 이벤트를 정의하기 때문에 HttpContext
대신 HttpApplication
를 사용해보십시오. 자세히보기 <./ P>
사용량
.HttpContext context = ((HttpApplication)sender).Context;