0
일부 오류가 발생했습니다. Richard Dingwall의 예를 VB.NET으로 변환 해 보았습니다. 문제는 내가 오류 받고 있어요 점이다ASP.NET - ResourceNotFoundException이 정의되지 않았습니다.
Type ResourceNotFoundException is undefined
'<AttributeUsage(AttributeTargets.[Class] Or AttributeTargets.Method, Inherited:=True, AllowMultiple:=False)> _'
Public NotInheritable Class HandleResourceNotFoundAttribute : Inherits FilterAttribute : Implements IExceptionFilter
Public Property View() As String
Public Sub New()
View = "NotFound"
End Sub
Public Sub New(ByVal _view As String)
View = _view
End Sub
Public Sub OnException(ByVal filterContext As ExceptionContext) Implements System.Web.Mvc.IExceptionFilter.OnException
Dim controller As Controller = TryCast(filterContext.Controller, Controller)
If controller Is Nothing OrElse filterContext.ExceptionHandled Then
Return
End If
Dim exception As Exception = filterContext.Exception
If exception Is Nothing Then
Return
End If
''# Action method exceptions will be wrapped in a
''# TargetInvocationException since they're invoked using
''# reflection, so we have to unwrap it.
If TypeOf exception Is TargetInvocationException Then
exception = exception.InnerException
End If
''# If this is not a ResourceNotFoundException error, ignore it.
''# ###############################
''# ###############################
If Not (TypeOf exception Is ResourceNotFoundException) Then ''# ERROR HERE
''# ###############################
''# ###############################
Return
End If
filterContext.Result = New ViewResult() With { _
.TempData = controller.TempData, _
.ViewName = View _
}
filterContext.ExceptionHandled = True
filterContext.HttpContext.Response.Clear()
filterContext.HttpContext.Response.StatusCode = 404
End Sub
End Class
마치 사용자 지정 구현이 단순히 선언하고 "예외"를 상속하는 것처럼 보이는 것처럼 보입니다. 'public class ResourceNotFoundException : Exception {}' –
아니, 맞아. 이와 같이 '빈'예외가있는 이유는 ResourceNotFound 예외와 다른 종류의 예외를 구별 할 수 있기 때문입니다 (예를 들어 Exception을 던졌을 때 핸들러 코드가 사용자가 계획하지 않은 모든 종류의 예외를 catch 할 수있는 경우 취급시) –