我正在尝试在 Global.asax 中为以下控制器设置路由,但我总是收到HTTP 错误 404.0 - Not Found
资产控制器.cs
public class AssetsController : Controller
{
public ActionResult Index(string aDesc, string fDate)
{
ViewBag.DateFrom = fDate.ToString();
ViewBag.AssetDescription = aDesc.ToString();
return View();
}
}
全球.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();
}
}
当我使用以下 URL 访问视图时,一切正常且符合预期:
http://localhost/Assets/Index/?aDesc=090&fDate=20130701000000
但是当我使用以下 URL 访问视图时,我收到 404.0 错误消息(错误如下所示)
http://localhost/Assets/Index/090/20130701000000
错误:HTTP 错误 404.0 - 未找到 您要查找的资源已被删除、名称已更改或暂时不可用。
AppPool 设置为 .NET 4.0 集成模式
HTTP 重定向和静态内容在 Common HTTP Features (Windows Features On/Off) 下被选中