简体   繁体   中英

Can ASP.NET MVC routing and a classic ASP homepage (VBScript, not web forms) play together nicely?

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 (eg, / ) 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!

UPDATE

I apologize for the delay in getting back to this but it went on the back burner for a while and I honestly almost forgot about this; however I did manage to get this working! I'd like to give credit to both Chris Marisic and Chance, since combined they helped me figure this out.

The problem was that sure enough, it seems there was a default route (as Chance suggested in a comment) that was catching these requests to the site root.

So, by tweaking this, and also adding routes.IgnoreRoute(""); (empty-string) as the first rule in my routing list, this now works!

Thank you everyone for your help!

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

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

Something along the lines of

routes.IgnoreRoute("/");

or

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

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}")

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.

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.

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.

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