views:

79

answers:

6

Hello,

We have a classic VBScript "default.asp" page in the root of our site. (This is a heavy, legacy page and converting it is not an option right now.) We also have a new ASP.NET MVC 2 application we want to host on the same site. Everything actually works great together! Except for one thing: requests to the root of the site (e.g., /) get picked up by the MVC routing (which then wants to display the HomeController's Index action) instead of letting the default.asp page take the request!

This is what I would like:
http://www.example.com/ <- should execute the classic default.asp page, not /Home/Index!

I can't figure out how to not execute HomeController.Index(). If I remove the HomeController, I get an error. If I try to IgnoreRoute("") I get an error. I have even changed the priority/order of the "default document" in IIS for this site to treat "default.asp" as the preferred document. I've even deleted the dummy MVC "default.aspx" page out of the root, and still the MVC routing is "stealing" requests for the root of the site.

The temporary solution is for me to have HomeController.Index redirect the user back to "default.asp". This works, but then it shows up ugly and visible in the address bar,
http://www.example.com/default.asp <- not what I want to show.

Any suggestions/answers on how to get these both to co-exist? Perhaps something I can add to web.config to make this specific exception for the homepage? Thank you!

+2  A: 

You want to add the home route to the ignore route list.

Something along the lines of

routes.IgnoreRoute("/");

or

routes.IgnoreRoute("/default.asp");

Chris Marisic
Thank you for your response, but unfortunately neither of these work. I had already tried the first, but it ends up completely breaking the rest of the site (since it matches *too* much I guess.) And the second one is what I'm trying to avoid, not handle! (I mentioned I do _not_ want default.asp to appear in the address bar.)
Funka
Why `routes.IgnoreRoute("/")` breaks the rest of the site? What kind of bad behaviors are you getting?
Eduardo Molteni
A: 

I'm not sure about this, but you should be able to add default.asp to your default file list (iis). From there, just make sure all of your routes have a prefix (ie: "something/{id}")

Chance
As noted in my question, Default.asp is already at the very top of the default documents list in IIS for this site. Thank you!
Funka
ah, missed that. Just make sure you do not have a route that can catch a base route. If you have routes like {controller}/{action}/{id} with all params defaulted, its going to catch that. Like I said, make sure you have prefixes on your MVC routes and it wont happen.
Chance
+2  A: 

This maybe not what your looking for, but what about trying something like the ASP Classic Compiler and add it to your Home Controler

http://aspclassiccompiler.codeplex.com/

Regards

Iain

Iain
wow, interesting project! thank you for the link!
Funka
A: 

the simplest way would be using a subdomain. i had a similar problem, my solution was to modify the asp-pages to render xml as output and screen scraped the output from the mvc application.

Snoopy
We would prefer to keep these on the same site and domain if possible. Thank you for the suggestion!
Funka
A: 

I think ignoring the route should work, though that behavior might lead to unintended consequences.

Crazy talk answer: move the page somewhere, make whatever action lives at "~/" turn around and make a WebRequest to that page and then send that as content to the browser.

Wyatt Barnett
I've tried ignoring the route, but then what I think happens is it ends up matching _everything_, so the MVC stuff that I do want to work no longer works.
Funka
P.S., I do like your "crazy talk" answer, it crossed my mind also! However it might be a little more involved due to classic ASP session cookies needing to get passed around. But still a possibility!
Funka
Sometimes hacks are fun. Try putting the ignore route after your routes. And definitely check out the MVC route debugger in the MVCContrib, it is a godsend for stuff like this.
Wyatt Barnett
A: 

I've just been dealing with this issue on our intranet.

Assuming that routes.RouteExistingFiles = false; The main problem is that MVC will take the base root as valid so IIS won't try to use default.asp so you need to try and break this somehow. My suggestions are:

Remove the Index route on your controller

Not just the Index route but also the default action that points to Index. If MVC doesn't match the root then IIS can try its defaults

Redirects

You could use the Index action method to give a RedirectResult to default.asp. It's an extra trip round but also means if/when you update that part of the application you just replace the index method.

URL rewriting

This is my preferred solution, use the IIS URL Rewrite module, it's quite powerful and gives you several options. you could get it to send a redirect back to the browser to the specific route. More interestingly you can get it to rewrite the URL to append the default.asp. This means MVC sees the url which includes the file but doesn't need to send the browser a redirect.

Chao