相关疑难解决方法(0)

如何让ELMAH使用ASP.NET MVC [HandleError]属性?

我正在尝试使用ELMAH来记录我的ASP.NET MVC应用程序中的错误,但是当我在控制器上使用[HandleError]属性时,ELMAH在发生错误时不会记录任何错误.

正如我猜测它,因为ELMAH只记录未处理的错误,[HandleError]属性正在处理错误,因此无需记录它.

我如何修改或如何修改属性,以便ELMAH可以知道有错误并记录它..

编辑:让我确保每个人都理解,我知道我可以修改那个不是我问的问题的属性... ELMAH在使用handleerror属性时会被绕过,这意味着它不会看到有错误因为它被处理了已经由属性...我要问的是有一种方法让ELMAH看到错误并记录它即使属性处理它...我搜索周围,没有看到任何方法调用强制它来记录错误....

asp.net-mvc logging elmah

562
推荐指数
7
解决办法
11万
查看次数

ASP.NET MVC - 如何抛出类似于StackOverflow上的404页面

我目前有一个继承自的BaseController类System.Web.Mvc.Controller.在那个类上我有HandleError属性,将用户重定向到"500 - 糟糕,我们搞砸了"页面.目前正在按预期工作.

这个工作

<HandleError()> _
Public Class BaseController : Inherits System.Web.Mvc.Controller

''# do stuff
End Class
Run Code Online (Sandbox Code Playgroud)

我还有我的404页面在Per-ActionResult的基础上工作,它再次按预期工作.

这个工作

    Function Details(ByVal id As Integer) As ActionResult
        Dim user As Domain.User = UserService.GetUserByID(id)

        If Not user Is Nothing Then
            Dim userviewmodel As Domain.UserViewModel = New Domain.UserViewModel(user)
            Return View(userviewmodel)
        Else
            ''# Because of RESTful URL's, some people will want to "hunt around"
            ''# for other users by entering numbers into the address.  We need to
            ''# gracefully redirect …
Run Code Online (Sandbox Code Playgroud)

asp.net routing handleerror http-status-code-404 asp.net-mvc-2

12
推荐指数
1
解决办法
4388
查看次数

ASP.NET MVC - 使用Reflection查找控制器是否存在

我有一点时间搞清楚如何正确实现我的404重定向.

如果我使用以下内容

<HandleError()> _
Public Class BaseController : Inherits System.Web.Mvc.Controller
''# do stuff
End Class
Run Code Online (Sandbox Code Playgroud)

然后页面上任何未处理的错误将加载"错误"视图,该视图效果很好. http://example.com/user/999(其中999是无效的用户ID)会在保留原始URL时抛出错误(这就是我想要的)

然而.如果有人将http://example.com/asdfjkl输入到url(其中asdfjkl是无效的控制器),则IIS将抛出通用404页面.(这不是我想要的).我需要的是上面要应用的相同内容.原始URL保留,并加载"NotFound"控制器.

我正在注册这样的路线

Shared Sub RegisterRoutes(ByVal routes As RouteCollection)
    routes.RouteExistingFiles = False
    routes.IgnoreRoute("{resource}.axd/{*pathInfo}")
    routes.IgnoreRoute("Assets/{*pathInfo}")
    routes.IgnoreRoute("{*robotstxt}", New With {.robotstxt = "(.*/)?robots.txt(/.*)?"})

    routes.AddCombresRoute("Combres")

    routes.MapRoute("Start", "", New With {.controller = "Events", .action = "Index"})

    ''# MapRoute allows for a dynamic UserDetails ID
    routes.MapRouteLowercase("UserProfile", "Users/{id}/{slug}", _
                             New With {.controller = "Users", .action = "Details", .slug = UrlParameter.Optional}, _
                             New With {.id = "\d+"} …
Run Code Online (Sandbox Code Playgroud)

reflection routing constraints asp.net-mvc-2

5
推荐指数
2
解决办法
3336
查看次数