简体   繁体   中英

Set web form as default page in an ASP.net MVC project

I have an Mvc project however i need a webform to be the startup page when a user goes to the site directly without specifying a page. I can use the "MapPageRoute" to take prioirty over the Default Mvc route if i call that code first like so.

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

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

The issue here is that although this redirects the site to the correct aspx page, it doesn't change the URL to home page so the url stays as something like "http://MySite/" when it should be "http://MySite/Members/MyHomePage.aspx"

The only other solution i see that will perform as desired is to create another controller and redirect to my web page in the action like below

public class HomeController : Controller
{
    public ActionResult Index()
    {


        Response.Redirect("~/Members/Requests.aspx");

        return View();
    }
}

and then setting this as the default in the global config like this

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

However this doesn't seem like good practice as i am creating a controller just to redirect to a web form for the homepage.

Am i looking at this the right way or is there a better option out there?

Try setting webform as start up page by right click on page and select set as start up page from the property menu.

I added new Item, then selected Webform type and just set it as start up page, no changes in route, its simply loading that webform as default with name of page on Url.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM