Set "Homepage" in ASP.NET MVC

Set Homepage in Asp.Net MVC

Look at the Default.aspx/Default.aspx.cs and the Global.asax.cs

You can set up a default route:

        routes.MapRoute(
"Default", // Route name
"", // URL with parameters
new { controller = "Home", action = "Index"} // Parameter defaults
);

Just change the Controller/Action names to your desired default. That should be the last route in the Routing Table.

How to set a default page on an MVC app?

looks like the most interesting bits are in the nopcommerce source code. the default route is registered as

    routes.MapLocalizedRoute("HomePage",
"",
new { controller = "Home", action = "Index"},
new[] { "Nop.Web.Controllers" });

you'll basically want to register your default route first, before the //register custom routes comment. should end up looking like this:

public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Catalog", action = "Category", id = 6 },
new[] { "Nop.Web.Controllers" }
);

routes.MapRoute(
"CustomHome", // Route name
"", // URL with parameters
new { controller = "Catalog", action = "Category", id = 6 },
new[] { "Nop.Web.Controllers" }
);

//register custom routes (plugins, etc)
var routePublisher = EngineContext.Current.Resolve<IRoutePublisher>();
routePublisher.RegisterRoutes(routes);

}

the first route may not even be necessary. i'm not sure. never worked with nopcommerce.

Change the Default page with MVC

From URL Rooting in ASP.NET (Web Forms) - chsakell's Blog, add this before the default MVC route:

routes.MapPageRoute("default", "", "~/Default.aspx");

You could also probably accomplish this using a filter, but it might be easiest just to do a redirect in the Index action of the HomeController.

public class HomeController : Controller
{
public ActionResult Index()
{
return Redirect("~/Default.aspx");
}
}

How to set MVC default page?

As you can see here: Index.aspx in a hybrid ASP.NET / ASP.NET MVC application

routes.MapPageRoute("DefaultPage", "", "~/Index.aspx"); 
routes.IgnoreRoute("{resource}.aspx/{*pathinfo}");

Setting Login page as default page in asp.net mvc 5

Your controller name is wrong. instead calling AccountController, you need to call Account.

public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapMvcAttributeRoutes();

routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Account", action = "Login", id = UrlParameter.Optional }
);
}

How to set default page in ASP.NET Core MVC and .NET 5?

Try this in your startup.cs file for default page:-

 app.UseEndpoints(endpoints =>
{

endpoints.MapControllerRoute(
name: "default",
pattern: "{area=StaffAug}/{controller=Login}/{action=Index}/{id?}"
);

});

For that, now your default page is Index view in your Login controller.

How to set default page asp.net

ASP.NET WebForms

On the web.config file, try this to use the clear tag before:

<system.webServer>
<defaultDocument>
<files>
<clear />
<add value="Pages/Home.aspx" />
</files>
</defaultDocument>
</system.webServer>

Take a look here: http://www.iis.net/configreference/system.webserver/defaultdocument

ASP.NET MVC / ASP.NET CORE

Depending of the version of asp.net mvc you are using, you can have it on a different file (~/Global.asax.cs in v3 or older or ~/App_Start/RouteConfig.cs in v4 or newer). In both cases, you will see something register the routes, because asp.net mvc uses routes instead files like webforms. So, you can change the default values:

public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new
{
controller = "Home", // default controller
action = "Index", // default action on the controller
id = UrlParameter.Optional
}
);
}

It is similar on the ASP.NET CORE.

Take a look here: http://www.codeproject.com/Articles/624181/Routing-Basics-in-ASP-NET-MVC



Related Topics



Leave a reply



Submit