mvc2将子域路由到区域不起作用

问题描述:

我正在使用此博客中的代码:http://blog.maartenballiauw.be/post/2009/05/20/ASPNET-MVC-Domain-Routing.aspx来实现子域名。我的目标是有一个区域/管理/与URL一起工作,如:admin.localhost \ test \ index,而我的主应用程序是localhost \ home \ index。mvc2将子域路由到区域不起作用

我已经实现了以下路线:

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) 

的观点没有定义母版页。

我刚才解决了这个问题,请检查my blog关于将子域路由到区域。

希望这会有所帮助