我正在使用此博客中的代码:http://blog.maartenballiauw.be/post/2009/05/20/ASPNET-MVC-Domain-Routing.aspx来实现子域名。我的目标是有一个区域/ admin /与url一起工作,例如:admin.localhost \ test \ index,而我的主应用程序是localhost \ home \ index。
我已实施以下路线:
context.Routes.Add("AdminDomainRoute", new DomainRoute(
"admin.localhost", // Domain with parameters
"{controller}/{action}/{id}", // URL with parameters
new { controller = "test", action = "index", id = "", isAdmin = true }
// Parameter defaults
));
区域/管理员有一个名为TestController的控制器和一个名为/Test/Index.aspx的视图。但是当我尝试去admin.localhost(在\ hosts文件中定义)时,我收到以下错误:
System.InvalidOperationException: The view 'index' or its master was not found. The following locations were searched:
~/Views/test/index.ascx
~/Views/Shared/index.ascx
~/Views/Admin/test/index.ascx
~/Views/test/index.aspx
~/Views/Shared/index.aspx
~/Views/Admin/test/index.aspx
~/Views/test/index
~/Views/Shared/index
~/Views/Admin/test/index
at System.Web.Mvc.ViewResult.FindView(ControllerContext context)
at System.Web.Mvc.ViewResultBase.ExecuteResult(ControllerContext context)
at System.Web.Mvc.ControllerActionInvoker.InvokeActionResult(ControllerContext controllerContext, ActionResult actionResult)
at System.Web.Mvc.ControllerActionInvoker.<>c__DisplayClass14.<InvokeActionResultWithFilters>b__11()
at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter, ResultExecutingContext preContext, Func`1 continuation)
at System.Web.Mvc.ControllerActionInvoker.<>c__DisplayClass14.<>c__DisplayClass16.<InvokeActionResultWithFilters>b__13()
at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters(ControllerContext controllerContext, IList`1 filters, ActionResult actionResult)
at System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName)
视图没有定义母版页。