Is it possible to remove a folder from the URL in ASP.NET MVC?
No.
MVC does not use files and folders to host its endpoints - it uses controllers and actions. Therefore, it is not possible to remove a "folder" from the URL, because there are no folders in the URL.
However, MVC uses .NET routing, which allows you to configure your URLs to look however you want. So, to make a route that matches /page
as per your example, you need to insert a route to match that URL to your RouteConfig.cs
file.
public class RouteConfig
{
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
// Route to domain.com/page that calls an action named Page on the HomeController
routes.MapRoute(
name: "PageRoute",
url: "page",
defaults: new { controller = "Home", action = "Page" }
);
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
}
}