How to set routes for a controller in MVC. Always returns "HTTP Error
404.0 - Not Found"
I am trying to set the route in Global.asax for the following controller,
but I always get HTTP Error 404.0 - Not Found
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();
}
}
When I access the view using the following URL, everything works fine and
as expected:
http://localhost/Assets/Index/?aDesc=090&fDate=20130701000000
But when I access the view using following URL, I get 404.0 error message
(error shown below)
http://localhost/Assets/Index/090/20130701000000
Error: HTTP Error 404.0 - Not Found The resource you are looking for has
been removed, had its name changed, or is temporarily unavailable.
AppPool is set to .NET 4.0 Integrated Mode
HTTP Redirection and Static Content is checked under Common HTTP Features
(Windows Features On/Off)
No comments:
Post a Comment