21472

Getting MVC default route to go to ~/default.asp

I am adding some MVC features to an existing site (FWIW, most of which is in classic ASP). As a result, I need to keep the default routing going to ~/default.asp (at a minimum - preferably the default document specified in IIS).

Is there a way to write the route in RegisterRoutes so that a request for the root of the site (e.g., http://localhost, http://localhost/, or http://localhost/default.asp) will directly get the default page, and not attempt to find a controller/action? Or do I need to write my own HttpModule that will filter it and keep it from getting to the MvcHandler (as in this blog)?

BTW, I have googled this, but most of the hits are for MVC version 1 or older, and default routing appears to have changed in version 2 (i.e, there is no more default.aspx that redirects to ~/Home), so they are not directly applicable. Even so, the ones that were there didn't address this problem.

Answer1:

Maarten Balliauw has written a nice artice about mixing ASP.NET Webforms and ASP.NET MVC. The thing you need from the article is the part where you tell MVC not to route certain routes:

In your case this would be:

routes.IgnoreRoute("default.asp/{*pathInfo}"); // If you don't pass arguments just use default.asp routes.IgnoreRoute("");

After these ignores, provide your regular MVC routes. This way MVC will ignore these routes and will let Webforms handle them. Provided that / will point to /default.asp in Webforms, this should work. However, I haven't tested this...

Recommend

  • Generate URL based off of the current URL and maintain QueryString
  • Routing by slug in asp.net mvc
  • ASP.NET MVC Routing strategy for static content for each View
  • Share session on subdomains in php
  • FolderBrowserDialog crashes the application
  • Kill Active Session if User Is Banned
  • ASP.NET Identity executes database query on every page request when logged in
  • Fraction length
  • Efficient User-Agent Regex to find Safari in Python
  • CORS with socket.io
  • mave 3.2 not able to access local nexus instance return 502 code
  • Tomcat memory Leak
  • Elasticsearch script query involving root and nested values
  • CakePHP ACL tutorial initDB function warnings
  • JBoss External Properties Files in Classpath
  • htaccess add www if not subdomain, if subdomain remove www
  • Sencha Touch 2.0 Controller refs attribute not working?
  • Typescript - Unable to get 'import' statement to function
  • Cannot resolve symbol 'MyApi'
  • Jenkins: How To Build multiple projects from a TFS repository?
  • How to redirect a user to a different server and include HTTP basic authentication credentials?
  • Running a C# exe file
  • htaccess rewriting URLs with multiple forward slashes
  • Symfony2: How to get request parameter
  • Display Images one by one with next and previous functionality
  • Web-crawler for facebook in python
  • bootstrap to use multiple ng-app
  • How to get icons for entities from eclipse?
  • A cron job substitute?
  • log4net write single file for each call to log.info
  • Getting error when using KSoap library to consume .NET web services
  • Turn off referential integrity in Derby? is it possible?
  • How can I remove ASP.NET Designer.cs files?
  • python draw pie shapes with colour filled
  • JaxB to read class hierarchy
  • Is there any way to bind data to data.frame by some index?
  • Running Map reduces the dimensions of the matrices
  • Binding checkboxes to object values in AngularJs
  • How can i traverse a binary tree from right to left in java?
  • How to load view controller without button in storyboard?