I use ASP.NET MVC 5 and this is My Route Map for all of the actions except Home/index
:
routes.MapRoute(
name: "randomNumber",
url: "{controller}/{randomNumber}/{action}",
defaults: new { },
constraints: new { randomNumber = @"\d+" }
);
And for first page: Home/Index
I don't want to use {randomNumber}
So the first solution I think is:
routes.MapRoute(
name: "Default",
url: "{controller}/{action}",
defaults: new { controller = "Home", action = "Index" }
);
This route map solve my problem, but caused another problem that is: clients can access to other actions without {randomNumber}
, but I just want the Index
action of Home
Controller accessed without random number.
The other Solution Is:
routes.MapRoute(
name: "Default",
url: "Home/Index",
defaults: new { controller = "Home", action = "Index" }
);
But with this map I can't access Home/index
with root url, I need to access Home/index
with root url like this: www.mydomainaddress.com
Finally i found this:
routes.MapRoute(
name: "Default",
url: "",
defaults: new { controller = "Home", action = "Index" }
);
But I got the Exception: No route in the route table matches the supplied values.
on index.cshtml
file in this line: @{Html.RenderAction("ArchiveList", "Home");}
I don't know the ralation of the route map that I added and RenderAction
helper?
But If I add both the following two route maps, everything will be OK:
routes.MapRoute(
name: "Default",
url: "",
defaults: new { controller = "Home", action = "Index" }
);
routes.MapRoute(
name: "HomeActions",
url: "Home/{action}",
defaults: new { controller = "Home" }
);
But I can't add the second map route as you know (I need all actions accessed with random number)
I can't understand what happened when I add the Default
map, and what related to RenderAction
helper?
Does any one have any idea about this? any suggestion?