Я работаю над некоторыми ошибками и попытался преобразовать пример Ричарда Дингволла в VB.NET.Проблема в том, что я получаю сообщение об ошибке:
Тип ResourceNotFoundException не определен
'<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