한 번만 실행하면되지만 외부 리소스에 의존적 인 코드가 실행되어 실패 할 수 있습니다. 이벤트 로그에 오류가 나타나길 원하지만 사용자가보고 싶지는 않습니다. 가능한 경우 사용자 지정 오류 페이지를 사용하지 않는 것이 좋습니다.오류가 발생하지만 오류가 발생했음을 사용자가 알 수없는 가장 깨끗한 방법 (사용자 정의 오류 페이지가 없음)
나는 예외를 잡아 자신의 이벤트 로그에 쓸 수 있지만 asp.net 이벤트 소스의 이름이 무엇인지 보증 할 수는 없다고 우려하고 있습니다. (프레임 워크 버전에 따라 변경되는 것으로 보입니다.) 또한 관리 권한이 필요하기 때문에 자체 이벤트 소스를 만들 수 없습니다. (
public void Init(HttpApplication context)
{
try
{
throw new Exception("test"); // This is where the code that errors would go
}
catch (Exception ex)
{
HttpContext.Current.Application.Add("CompilationFailed", ex);
}
}
private void context_BeginRequest(object sender, EventArgs e)
{
if (HttpContext.Current.Application.AllKeys.Contains("CompilationFailed"))
{
// It failed on Init - we can't throw an exception there so lets try it here
var origEx = (Exception)HttpContext.Current.Application["CompilationFailed"];
// Only ever do this once
HttpContext.Current.Application.Remove("CompilationFailed");
// This should just look like a normal page load to the user
// - it will be the first request to the site so we won't be
// interrupting any postbacks or anything
HttpContext.Current.Response.AddHeader("Location", "/");
HttpContext.Current.Response.StatusCode = 301;
try
{
HttpContext.Current.Response.End();
}
catch (ThreadAbortException ex)
{
throw origEx;
}
}
}
을 이상적으로 내가 좋아 정말 할 것은 RecordException입니다 :
나는 현재 향해 노력하고있어 접근 방법은 (아직 작동하지 않습니다) 그것은 다음과 같습니다 해킹의 비트가) 메서드가있는 경우 IIS 내에서 사용할 수 있습니다.
EnterpriseLoggingLibrary는 이와 같은 항목에 적합합니다. 데이터베이스, Windows 이벤트 로그, 텍스트 파일 또는 기타 생각할 수있는 항목에 예외를 기록 할 수 있습니다. –