404 Error
上的 https://localhost:44300/services
。
导致此路由问题的原因是什么?
我无法理解的是https://localhost:44300/
和& https://localhost:44300/articles
是唯一有用的东西。
https://github.com/josephmcasey/me
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 }
);
}
}
}
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 }
);
}
}
}
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);
}
}
}
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();
}
}
}
@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 = "";
}
<section class="bg-lake light row shelve">
</section>
答案 0 :(得分:0)
如果您使用默认的ASP.Net MVC 5项目,那么这可能对您有用。首先,RouteDebugger Nuget Package即使在上次更新后3年也是一个很好的工具。它很容易指出我的错误。
首先,请注意AreaRegistration.RegisterAllAreas();
之前放置RouteConfig.RegisterRoutes(RouteTable.Routes);
的方式。路由按其接收的路由配置顺序优先。 AreaRegistration优先于RouteConfig。
接下来,Article and Portfolio areas
使用与
// default route (last)
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
因此,由于ArticleAreaRegistration首先出现,这两者之后的服务路线将无效。