开发者

ASP.NET - ResourceNotFoundException is Undefined

I'm working through some Error stuff, and I've tried converting Richard Dingwall's example over to VB.NET. The problem is that I'm getting an error:

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


If you read into Richard Dingwall's post (which I assume is this one), you'll notice that the ResourceNotFound exception is a custom exception which he has created, and provided code for. You'll need to implement that exception class yourself in order for the compiler to recognize that class.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜