IT Nota

  • Home
  • How To
  • .NET
  • WordPress
  • Contact
Home » .NET » Set Default Start Page to Web Forms on a Hybrid MVC and Web Forms Application

Set Default Start Page to Web Forms on a Hybrid MVC and Web Forms Application

As one of ASP.NET developers ever asked to upgrade an existing ASP.NET WebForms 3.5 application to ASP.NET 4 and added ASP.NET MVC pages to it, I found the tip, Integrating ASP.NET MVC 3 into existing upgraded ASP.NET 4 Web Forms Applications from Scott Hanselman very helpful.

After I followed all the steps provided, I was still baffled by the inconsistent behavior of the web app itself. When the app is run on ASP.NET Development Server locally, the default landing page is my default.aspx, which is the intended result. For some reason, every time I deploy it to production, the default changes to the Index action in MVC 3 HomeController.

It must be the combination of me being a novice in MVC 3 and ASP.NET routing altogether that I had to struggle with this issue for at least a few days before finding out that the solution actually was as simple as reversing the order of my ASP.NET routing.

Here’s what I originally had in my Global.asax.cs:

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

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

  // Web Forms default
  routes.MapPageRoute(
    "WebFormDefault",
    "",
    "~/default.aspx");
}

Here’s what I have now that fixes the issue on the production:

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

  // Web Forms default
  routes.MapPageRoute(
    "WebFormDefault",
    "",
    "~/default.aspx");

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

So that was the only thing I needed to do to fix the problem. The only unsolved mystery for me is I still have no answer on why the ASP.NET Development Server seems to default to the web forms automatically while the IIS 7.5 is more nitpicky about it.

Further Reading

ASP.NET Routing

December 27, 2011 Filed Under: .NET, How To Tagged With: MVC

Comments

  1. Borza József says

    January 4, 2019 at 4:52 pm

    not Global.asax.cs but RouteConfig.cs

    Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Categories

  • .NET
  • Coding
  • Database
  • How To
  • Internet
  • Multimedia
  • Photography
  • Resources
  • Review
  • WordPress
  • Writing

Recent Posts

  • How to Use Custom Color in SSMS Using Redgate SQL Prompt
  • How to Install Python on Windows Server
  • How to Enable Secure HttpOnly Cookies in IIS
  • How to Create iCloud Mail Email Address
  • How to Import IIS Log to PostgreSQL
Genesis Framework for WordPress

Recent Posts

  • How to Use Custom Color in SSMS Using Redgate SQL Prompt
  • How to Install Python on Windows Server
  • How to Enable Secure HttpOnly Cookies in IIS
  • How to Create iCloud Mail Email Address
  • How to Import IIS Log to PostgreSQL
  • RSS

Tags

.NET Core Access Adobe AdSense Amazon ASP.NET Cdonts Dll Classic ASP Code Editor Connect-It Copywriting ETL Genesis Framework Git Google HP Asset Manager HTML HTML5 Hugo IIS Information Security Internet Internet Information Services iOS Linux macOS Microsoft Microsoft SQL Server MVC Nikon Oracle PHP Simple Mail Transfer Protocol Smtp Server Social Media SQL SQL Server SSIS SSMS SSRS Windows Windows 8 Windows 10 Windows 2012 Windows Server

Copyright © 2011-2019 IT Nota. All rights reserved. Terms of Use | Privacy Policy | Disclosure