I have multiple route controls for multiple actions in my web application.
This actions is called by parameter-
routes.MapRoute(
name: "SpecificRoute",
url: "{BusinessName}",
defaults: new { controller = "Business", action = "OpenPage" }
);
This one is called via action name and parameter-
routes.MapRoute(
name: "ResumeRoute",
url: "{action}/{PublicResume}",
defaults: new { controller = "Business", action = "PublicResume" }
);
And for all default actions I already have one route control by default-
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{*id}",
defaults: new { controller = "WelcomeLedger", action = "Welcome", id = UrlParameter.Optional }
);
I have deployed this application on local IIS server.
Now there is something went wrong with route.config file, Maybe I am not using routes in proper manner.
So this application shows me resource not found error on every action and sometimes it works after cleaning the solution.
How can I use actions without breaking their manner of usage?
This is my route.config file-
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Http;
using System.Web.Mvc;
using System.Web.Routing;
namespace MvcApplication8 {
public class RouteConfig {
public static void RegisterRoutes(RouteCollection routes) {
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.IgnoreRoute("{*favicon}", new { favicon = @"(.*/)?favicon.ico(/.*)?" });
routes.MapRoute(
name: "SpecificRoute",
url: "{BusinessName}",
defaults: new { controller = "Business", action = "OpenPage" }
);
routes.MapRoute(
name: "ResumeRoute",
url: "{action}/{PublicResume}",
defaults: new { controller = "Business", action = "PublicResume" }
);
routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{*id}",
defaults: new { controller = "WelcomeLedger", action = "Welcome", id = UrlParameter.Optional }
);
}
}
}
EDIT-
Default routes not found (resource not found) after adding two custom routes above it.
I think you have a typo in your default route:
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{*id}",
defaults: new { controller = "WelcomeLedger", action = "Welcome", id = UrlParameter.Optional }
);
There is a * before id, it should be {id} instead of {*id}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With