where is the default page in mvc3?

2019-05-05 06:53发布

问题:

I am not certain how a domain can load a test when there is no default document like default.aspx in root. Is in the "global.asax" ? where is the default page in mvc3?

回答1:

You're gonna find that in Views/Home/

The index page

Mvc works through the controller - model - view model

When you create a default project you will find that the global.asax has the following code:

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

This means that the Default page is the Index action in the Home controller.

You can access other pages by this example: If you have an AccountController with a Login view, it means you can access the login page by going to /Account/Login.



回答2:

By default, the default page is rendered by the home controller's index action. The html is in /Views/Home/index.cshtml.

This is configured in the Global.asax in the RegisterRoutes method.



回答3:

Besides what Lauw already mentioned.

If you are using basic forms authentication and you want another default page than Home you might want to change the redirects inside AccountController, e.g. change

  public ActionResult LogOff()
  {
     FormsAuthentication.SignOut();

     return RedirectToAction("Index", "Home");
  }

to something like

 public ActionResult LogOff()
  {
     FormsAuthentication.SignOut();

     return RedirectToAction("LogOn", "Account");
  }

The same for LogOn and Register. If you don't do this you'll end up with user arriving at the old Home page accidentally.