I have an asp.net mvc 1.0 site that serves some content from a 2 level hierarchy /category/article
When things work right the article maps to a view and the view gets rendered. However, when the url meets the routing condition but the view doesn't exist an exception is raised that I can't trap in the Controller action.
Routing:
routes.MapRoute(
"Article",
"{category}/{article}.aspx",
new { controller = "MyController", action = "Article" }
);
MyController Action:
public ActionResult Article(string category, string article)
{
string path = string.Format("~/Views/{0}/{1}.aspx", category, article);
ViewResult vr = View(path);
return vr;
}
However, when the view is not found, a System.InvalidOperationException is generated that I can't catch in the Controller Action.
Exception Details: System.InvalidOperationException: The view '~/Views/my-category/my-article-with-long-name.aspx' or its master could not be found. The following locations were searched:
~/Views/my-category/my-article-with-long-name.aspx
I can trap the error in the Application_Error() method in global.asax.cs but: 1) don't know how to redirect to the error view from there 2) wonder if there is a better place closer to where the exception is raised.