我一直在设置一个使用 MVC Turbine 运行的项目,并且在调用 IRouteRegistrators 时遇到了问题。我团队中的另一个人过去曾遇到过这个问题,但他不记得他必须做什么才能解决它。
设置代码暂时全部在 Global.asax.cs 文件中,直到解决。我使用的代码看起来与我见过的每个教程都相似,但无论如何它都包含在下面。
public class MvcApplication : TurbineApplication
{
static MvcApplication()
{
ServiceLocatorManager.SetLocatorProvider (() => new StructureMapServiceLocator ());
}
protected void Application_Start ()
{
DeployDbMigrations ();
}
private void DeployDbMigrations ()
{
...
}
}
public class RouteRegistration : IRouteRegistrator
{
public void Register (RouteCollection routes)
{
routes.IgnoreRoute ("{resource}.axd/{*pathInfo}");
routes.MapRoute (
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
);
}
}
正如我所说,没有调用 IRouteRegistrator,所以当我转到主页时,即使设置了正确的控制器和视图,我也会得到 404。
烦人的是,我可以在当前解决方案之外创建一个类似的项目,它会工作,但它不会在解决方案中工作。(虽然,我尝试将工作项目复制粘贴到解决方案中并且有效。但是,这不再是一种选择,因为在我弄清楚这一点时,其他人已经在 Web 项目上做了更多的工作。)
过去有没有人遇到过这个问题,和/或知道如何解决它?