IT Nota

  • Home
  • How To
  • .NET
  • WordPress
  • Contact

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

Buy me a coffee?

Buy me a coffee If you find any of the articles or demos helpful, please consider supporting my work here, you'll have my big thanks!

Buy me a coffee Support this site
Buy Me a Coffee?

Categories

  • .NET
  • Coding
  • Cybersecurity
  • Database
  • How To
  • Internet
  • Multimedia
  • Photography
  • Programming
  • Resources
  • Review
  • Tips and Tricks
  • Uncategorized
  • Use Case
  • WordPress
  • Writing

Recent Posts

  • How to View Stored Procedure Code in SQL Server
  • How to Find a String in SQL Server Stored Procedures
  • How to Remove Cached Credentials without Rebooting Windows
  • ESP Work Automation: Empowering Enterprises with Streamlined Workflows and Operational Efficiency
  • How to Search for a String in All Tables in a Database

Recent Posts

  • How to View Stored Procedure Code in SQL Server
  • How to Find a String in SQL Server Stored Procedures
  • How to Remove Cached Credentials without Rebooting Windows
  • ESP Work Automation: Empowering Enterprises with Streamlined Workflows and Operational Efficiency
  • How to Search for a String in All Tables in a Database

Tags

.NET .NET Core AdSense ASP.NET Cdonts Dll Classic ASP Code Editor ETL FSharp Genesis Framework Git Google HP Asset Manager HTML5 Hugo IIS Information Security Internet Internet Information Services iOS JAMStack Linux macOS Microsoft Microsoft SQL Server MVC PHP PowerShell Python Simple Mail Transfer Protocol Smtp Server SQL SQL Server SSIS SSMS SSRS Sublime Text Visual Studio Visual Studio Code VPN Windows Windows 8 Windows 10 Windows 2012 Windows Server

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