获取MVC默认路由转到〜/default.asp [英] Getting MVC default route to go to ~/default.asp

查看:71
本文介绍了获取MVC默认路由转到〜/default.asp的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在向现有站点(FWIW,其中大多数是经典ASP)添加一些MVC功能.因此,我需要将默认路由保留为〜/default.asp(至少-最好是IIS中指定的默认文档).

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).

有没有一种方法可以在RegisterRoutes中写入路由,以便对站点根目录的请求(例如, http://localhost http://localhost/ http://localhost/default.asp )将直接获取默认页面,而不尝试查找控制器/动作?还是我需要编写自己的HttpModule来对其进行过滤,并阻止其进入MvcHandler(如

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)?

顺便说一句,我已经用谷歌搜索了,但是大多数匹配是针对MVC版本1或更旧版本的,并且默认路由在版本2中似乎已更改(即,没有更多的default.aspx重定向到〜/Home) ,因此它们并不直接适用.即使这样,在那里的人也没有解决这个问题.

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.

推荐答案

Maarten Balliauw写了一篇关于

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("");

在忽略这些内容之后,请提供常规的MVC路由.这样,MVC将忽略这些路由,并让Webforms处理它们.前提是/将指向Webforms中的/default.asp,这应该可以工作.但是,我还没有对此进行测试...

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...

这篇关于获取MVC默认路由转到〜/default.asp的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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