是否可以将所有控制器都用于ControllerFactory?
我想要做的是获取应用程序中所有控制器类型的列表,但是以一致的方式.
因此,我得到的所有控制器都是默认的请求解决方案正在使用.
(实际任务是查找具有给定属性的所有操作方法).
我目前有一个继承自的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
我有一个MVC 2应用程序,应该总是提供一个"漂亮的"404页面.
但是目前我得到了一个低级别的.Net:"'/ sitename'应用程序中的服务器错误..."
我有一个基本控制器,它有一个NotFound动作,将呈现漂亮的404页面.
处理缺失的操作:
protected override void HandleUnknownAction(string actionName)
{
this.NotFound(actionName).ExecuteResult(this.ControllerContext);
}
Run Code Online (Sandbox Code Playgroud)
所以访问{site}/ValidController/NotAnAction正确地路由.
但是访问{site}/NotAController没有.
我设置的路线全部为:
routes.MapRoute(
"MVC routes",
"{controller}/{action}/{id}",
new { action = "Index", id = UrlParameter.Optional });
routes.MapRoute(
"Catch All",
"{*url}",
new { controller = "System", action = "NotFound" });
Run Code Online (Sandbox Code Playgroud)
catch全部正确捕获不匹配的路由.
所以{site}/Invalid/Action/id/extra通过catch all正确路由.
然而{site}/Invalid,通过"MVC路由"路由获取并且ASP.Net寻找InvalidController,并且当它找不到时抛出一个愚蠢的异常.
我知道我可以在web.config关卡中覆盖它,但这只是重定向到页面.我想知道路由模式何时匹配但控制器不是有效的控制器名称.
我在哪里可以捕捉并改变这种行为?