【发布时间】:2015-08-08 09:19:00
【问题描述】:
问题
当页面和路由存在时,404 Error on https://localhost:44300/services。
问题
是什么导致了这个路由问题?
注意观察
我无法理解的是 https://localhost:44300/ 和 https://localhost:44300/articles 之类的目录是如何工作的。
GitHub 项目
https://github.com/josephmcasey/me
感兴趣的文件
/Areas/Article/ArticleRegistrationArea.cs
using System.Web.Mvc;
namespace JosephMCasey.Areas.Article
{
public class ArticleAreaRegistration : AreaRegistration
{
public override string AreaName
{
get
{
return "Article";
}
}
public override void RegisterArea(AreaRegistrationContext context)
{
context.MapRoute(
"Article",
"{controller}/{action}/{id}",
new { action = "Index", id = UrlParameter.Optional }
);
}
}
}
/App_Start/RouteConfig.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;
namespace JosephMCasey
{
public class RouteConfig
{
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.IgnoreRoute("images/{*pathInfo}");
routes.IgnoreRoute("ckeditor/{*pathInfo}");
// access TermsController/Index via /terms
routes.MapRoute(
name: "Terms",
url: "terms",
defaults: new { controller = "Terms", action = "Index" }
);
// access PrivacyController/Index via /privacy
routes.MapRoute(
name: "Privacy",
url: "privacy",
defaults: new { controller = "Privacy", action = "Index" }
);
// access ServicesController/Index via /services
routes.MapRoute(
name: "Services",
url: "services",
defaults: new { controller = "Services", action = "Index" }
);
// access ErrorController/NotFound via /404
routes.MapRoute(
name: "NotFound",
url: "404",
defaults: new { controller = "Error", action = "Index" }
);
// default route (last)
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
}
}
}
/Global.asax
using System.Web;
using System.Web.Http;
using System.Web.Mvc;
using System.Web.Optimization;
using System.Web.Routing;
namespace JosephMCasey
{
public class MvcApplication : HttpApplication
{
protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();
GlobalConfiguration.Configure(WebApiConfig.Register);
FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
RouteConfig.RegisterRoutes(RouteTable.Routes);
BundleConfig.RegisterBundles(BundleTable.Bundles);
}
}
}
/Controllers/ServicesController.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.Mvc;
namespace JosephMCasey.Controllers
{
//[Authorize]
[AllowAnonymous]
public class ServicesController : Controller
{
[AllowAnonymous]
public ActionResult Index()
{
return View();
}
}
}
/Views/Services/index.cshtml
@section SPAViews {
@Html.Partial("_Services")
}
@section Scripts{
@*
@Scripts.Render("~/bundles/knockout")
@Scripts.Render("~/bundles/app")
*@
}
@{
ViewBag.Title = "Privacy";
ViewBag.Keywords = "";
ViewBag.Description = "";
ViewBag.Created = "";
ViewBag.Thumbnail = "";
ViewBag.Image = "";
ViewBag.TwitterCard = "";
ViewBag.Site = "";
ViewBag.URL = "";
ViewBag.ImageHeight = "";
ViewBag.ImageWidth = "";
ViewBag.Site = "";
ViewBag.Creator = "";
ViewBag.OGType = "";
}
/Views/Services/_Services.cshtml
<section class="bg-lake light row shelve">
</section>
【问题讨论】:
-
您是否尝试过使用 RouteDebugger(nuget 包)来查看您期望被命中的路由是否是路由实际命中的路由?
-
我没有。我什至不知道这件事。我一直在使用 CodeMaid 和 Web Essentials。我一定会检查一下,看看它是否带来了什么。我最大的问题是在没有错误消息的情况下修复某些内容。
-
谢谢@KarenB!因为你,我得到了答案!
标签: c# asp.net asp.net-mvc routes http-status-code-404