38. 惓悋
public class MyExceptionAttribute: FilterAttribute, IExceptionFilter
{
public void OnException(ExceptionContext filterContext)
{
if (!filterContext.ExceptionHandled &&
filterContext.Exception is NullReferenceException)
{
filterContext.Result =
new RedirectResult("/MyError.html");
filterContext.ExceptionHandled = true;
}
}
}
40. Areas
public class AdminAreaRegistration : AreaRegistration {
public override string AreaName {
get { return "Admin"; }
}
public override void RegisterArea(AreaRegistrationContext context)
{
context.MapRoute(
"Admin_default",
"Admin/{controller}/{action}/{id}",
new { action = "Index", id = UrlParameter.Optional }
);
}
}
To be clear, it is not that the value of id is null when no
corresponding segment is supplied; rather, the case is that an id variable is not defined
To distinguish if user sent a value or not
Separation of concerns (defaults in routing?)