这个问题可能已经被问过了,但在阅读了这里, 这里, 这里和这里之后,我无法推断出相关的部分以使其正常工作。我正在将一个旧的网页表单站点改为MVC,并想要捕获特定的传入HTTP请求,以便我可以发出
与其拦截所有传入请求或解析某些
RedirectPermanent
(以保护我们的Google排名并避免用户因404而离开)。与其拦截所有传入请求或解析某些
id
值,我需要拦截所有以(或包含).aspx文件扩展名结尾的请求,例如:www.sample.com/default.aspx
www.sample.com/somedir/file.aspx
www.sample.com/somedir/file.aspx?foo=bar
应忽略对MVC路由的请求(仅按正常方式处理)。
这是我目前的情况,除了ASPXFiles
路由从未被触发。
public class RouteConfig
{
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
// never generates a match
routes.MapRoute(
name: "ASPXFiles",
url: "*.aspx",
defaults: new { controller = "ASPXFiles", action = "Index" }
);
// Used to process all other requests (works fine)
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
}
}
}
这种类型的路由在MVC中是否可以设置?
RedirectAspxPermanentRoute
类 - 构造函数签名已更改,以及它如何将路由值传递给控制器。 - NightOwl888StringComparer.OrdinalIgnoreCase
。因此,在您的RouteConfig
中,使用new Dictionary<string, object>(StringComparer.OrdinalIgnoreCase)
。 - CrnaStena