【发布时间】:2014-05-04 14:47:07
【问题描述】:
我有一个空的 ASP.NET 应用程序并添加了一个 index.html 文件。我想将 index.html 设置为网站的默认页面。
我试图右键单击 index.html 并设置为起始页,当我运行它时,url 是:http://localhost:5134/index.html 但我真正想要的是当我输入:http://localhost:5134 时,它应该加载index.html 页面。
我的路线配置:
public class RouteConfig
{
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
}
}
【问题讨论】:
-
你的动作“索引”在哪个控制器上?是在“家”控制器吗?
-
我在应用程序中只有一个控制器:公共类 MainController:控制器
-
好的,所以试着把
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }改成defaults: new { controller = "Main", action = "Index", id = UrlParameter.Optional } -
我不知道这是否区分大小写,如果真正的操作名称是'index',请小心
action = "Index" -
这个网址“localhost:5134”是否仍然呈现索引页面?如果是,那么您需要在解决方案>属性>Web>开始操作>特定页面中设置起始页
标签: asp.net-mvc asp.net-mvc-routing