Reputation: 776
Let's say I have following simple controller:
public class DataController: Controller
{
[HttpGet]
public ActionResult Index()
{
// some code
}
}
Now I'd like Index
action to be allways called if there is a GET request to DataContoller. I other words to ignore action name and any other parameters. For example all of following calls should be handled by Index
action:
How can I achieve this?
Upvotes: 0
Views: 702
Reputation: 2313
You should update your RouteConfig
like so:
public class RouteConfig
{
public static void RegisterRoutes(RouteCollection routes)
{
routes.MapRoute(
name: "RouteOverwrite",
url: "data/{*catchall}",
defaults: new { controller = "Data", action = "Index" }
);
}
}
Make sure you use this in Application_Start
:
public class MvcApplication : System.Web.HttpApplication
{
protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();
System.Net.ServicePointManager.SecurityProtocol = (SecurityProtocolType)3072;
// register route config
RouteConfig.RegisterRoutes(RouteTable.Routes);
}
}
Upvotes: 3
Reputation: 103
you can do this by using routetable. check out system.web.routing in asp.net mvc.
Upvotes: 0