这个问题已经在这里有一个答案:
This is how my project is structured我只有所谓的“家”的一个领域。我想我的主页是“/首页/门户网站/索引”
这是我的RouteConfig.cs:
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "Default",
url: "{area}/{controller}/{action}/{id}",
defaults: new {area = "Home", controller = "Portal", action = "Index", id = UrlParameter.Optional }
);
}
当我运行我的应用程序的方法“索引”中的“门户”被调用。 IIS没有找到我的观点,因为它是搜索“〜/查看/”而不是在“〜/地区/主页/浏览/”我不明白为什么。
TL:DR
本地主机/ <=不工作
本地主机/主页/门户网站/索引<=作品
谢谢阅读
编辑:的Application_Start()
public class MvcApplication : System.Web.HttpApplication
{
protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();
RouteConfig.RegisterRoutes(RouteTable.Routes);
BundleConfig.RegisterBundles(BundleTable.Bundles);
//Autofac
ContainerBuilder builder = new ContainerBuilder();
builder.RegisterControllers(typeof(MvcApplication).Assembly);
RepositoryBuilder.Register(builder);
ServiceBuilder.Register(builder);
new AutofacContainer(builder.Build());
DependencyResolver.SetResolver(new AutofacDependencyResolver(AutofacContainer.Instance));
//Automapper
AutoMapperConfig.Configure();
}
}
您需要Application_Start
注册您的地区:
AreaRegistration.RegisterAllAreas();