调试我的标题链接时出现以下错误。
我尝试重新创建我的Index.cshtml(空和Razor / HTML)和我的ServicesController。如果我显式浏览到Services / Index,那么页面会正确加载。
IE:localhost:58069 / Services /不起作用但localhost:58069 / Services / Index
我的其他控制器使用相同的结构和ActionLink助手正常工作。
不工作的代码:
public class ServicesController : Controller
{
// GET: Services
public ActionResult Index()
{
return View();
}
}
操作链接服务/索引的HTML帮助程序
<li>@Html.ActionLink("Services", "Index", "Services")</li>
工作守则
public class HomeController : Controller
{
// GET: Home/Index
public ActionResult Index()
{
return View();
}
}
工作助手
<li>@Html.ActionLink("Welcome", "Index", "Home")</li>
路线配置
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 }
);
}
尝试了以下SO解决方案:
此行为是由项目中的Services文件夹(在Scripts文件夹下)引起的。在IIS中托管时,不应该有与ASP.NET路由同名的文件或文件夹。
解决这个问题的方法:
routes.RouteExistingFiles = true;
将让ASP.NET处理所有路由我建议使用后一个选项,因为设置RouteExistingFiles
为true需要进行额外的研究以仔细检查你是不是打开了任何安全漏洞并且它清理了你的web项目(一点点分离永远不会伤害)。