我想設置爲以下控制器在Global.asax中的路線,但我總是得到HTTP錯誤404.0 - 找不到如何在MVC中爲控制器設置路由。始終返回「HTTP錯誤404.0 - 未找到」
AssetsController.cs
public class AssetsController : Controller
{
public ActionResult Index(string aDesc, string fDate)
{
ViewBag.DateFrom = fDate.ToString();
ViewBag.AssetDescription = aDesc.ToString();
return View();
}
}
的Global.asax.cs
public class MvcApplication : System.Web.HttpApplication
{
public static void RegisterRoutes(RouteCollection routes)
{
routes.MapRoute("Assets", "Assets/{action}/{aDesc}/{fDate}",
new { controller = "Assets", action = "Index", aDesc = "", fDate = "" }
);
// Show a 404 error page for anything else.
routes.MapRoute("Error", "{*url}",
new { controller = "Error", action = "404" }
);
}
protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();
WebApiConfig.Register(GlobalConfiguration.Configuration);
FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
RouteConfig.RegisterRoutes(RouteTable.Routes);
BundleConfig.RegisterBundles(BundleTable.Bundles);
AuthConfig.RegisterAuth();
}
}
當我ACCE SS使用以下URL的觀點,一切工作正常,並預期:
http://localhost/Assets/Index/?aDesc=090&fDate=20130701000000
但是,當我使用以下網址訪問的觀點,我得到404.0錯誤信息(如下圖所示的錯誤)
http://localhost/Assets/Index/090/20130701000000
錯誤:HTTP錯誤404.0 - 未找到您正在查找的資源已被刪除,其名稱已更改或暫時不可用。
程序池設置爲.NET 4.0集成模式
HTTP重定向和靜態內容是根據常見HTTP功能檢查(Windows功能開/關)
我不知道這個問題有什麼做的的WebAPI設置和事實的WebAPI的路線正在建立第一個註冊的路線? – JayC
JayC我不得不在RouteConfig.cs中註冊路由來修復它。謝謝。 – Learner