ASP.NET MVC路由和经典的ASP主页(VBScript,而不是Web表单)可以很好地协同工作吗? [英] Can ASP.NET MVC routing and a classic ASP homepage (VBScript, not web forms) play together nicely?

查看:118
本文介绍了ASP.NET MVC路由和经典的ASP主页(VBScript,而不是Web表单)可以很好地协同工作吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们网站的根目录中有一个经典的VBScriptdefault.asp页面。 (这是一个繁重的遗留页面,现在转换它不是一个选项。)我们还有一个新的ASP.NET MVC 2应用程序,我们想要在同一个站点上托管。一切都在一起很棒!除了一件事:对网站根目录的请求(例如, / )被MVC路由选择(然后想要显示HomeController的Index操作)而不是让default.asp页面接受请求!

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!

这就是我想要的:

http://www.example.com/ < - 应该执行经典的default.asp页面,而不是/ Home / Index!

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

我无法弄清楚如何执行 HomeController.Index()。如果我删除HomeController,我会收到一个错误。如果我尝试IgnoreRoute()我会收到错误。我甚至更改了IIS中默认文档的优先级/顺序,以便将default.asp视为首选文档。我甚至从根目录中删除了虚拟MVCdefault.aspx页面,但MVC路由仍在窃取对站点根目录的请求。

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.

临时解决方案是让HomeController.Index将用户重定向回default.asp。这有效,但在地址栏中显示丑陋和可见,

http ://www.example.com/default.asp < - 不是我要展示的内容。

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.

有关如何获取这些内容的任何建议/答案两者并存?也许我可以添加到web.config来为主页制作这个特定的例外?谢谢!

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!

我为延迟回到这个而道歉但它又回来了燃烧了一会儿,老实说,我差点忘了这个;但是我确实设法让这个工作!我想赞扬Chris Marisic和Chance,因为他们帮我解决了这个问题。

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.

问题是肯定的,似乎有一个正在将这些请求捕获到站点根目录的默认路由(如评论中的Chance所建议)。

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.

所以,通过调整这个,并添加 routes.IgnoreRoute(); (空字符串)作为我的路由列表中的第一条规则,现在可行了!

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

谢谢大家的帮助!

推荐答案

你想要将主路线添加到忽略路线列表。

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

routes.IgnoreRoute(/);

routes.IgnoreRoute(/ default.asp);

这篇关于ASP.NET MVC路由和经典的ASP主页(VBScript,而不是Web表单)可以很好地协同工作吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆