In my Controllers folder i want to have a subfolder called Admin.
When i go to http://localhost:port/Admin/Login/ it says the page could not be found.
RouteConfig.cs
using System.Web.Mvc;
using System.Web.Routing;
namespace ICT4Events
{
public class RouteConfig
{
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
}
}
}
You could use the next route to handle your issue:
routes.MapRoute(
name: "AdminSubForder",
url: "admin/{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
DON'T FORGET to change default value for controller = "Home"
to controller where you want to redirect when user types http://localhost:port/Admin/
.
So when you go to http://localhost:port/Admin/Login/
you will use Login
controller and Index
action in the Admin folder.
IMPORTANT
Also put this route BEFORE default route, because if you put this code after your "Default" route ASP.NET will read your http://localhost:port/Admin/Login/
like URL with Admin
controller and Login
action.
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