ASP.NET MVC:许多路由->总是只有一个控制器 [英] ASP.NET MVC: Many routes -> always only one controller

查看:18
本文介绍了ASP.NET MVC:许多路由->总是只有一个控制器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个非常简单的问题.我的站点基于 ASP.NET MVC,可以有许多 url,但所有这些都应该带到一个控制器上.该怎么做?

I have very simple question. My site, based on ASP.NET MVC, can have many urls, but all of them should bring to the one controller. How to do that?

我想我在 Global.asax 中需要一些魔法,但我不知道如何创建将任何 url 重定向到特定控制器的路由.

I suppose I need some magic in Global.asax but I don't know how to create route that will redirect any url to the specific controller.

例如,我有 url/about、/product/id 等,但所有这些都应该真正带到内容/显示中,其中 url 的部分将被识别,并决定将显示哪些信息.当您无法提前定义路线时,它有点像 CMS.这些信息够吗?

For example I have url /about, /product/id etc. but all of them should be really bring to the content/show where the parts of url will be recognized and the decision what information to show will be make. It's some like CMS when you cannot define routes in advance. Is this information enough?

谢谢

推荐答案

这听起来是个可怕的想法,但是,如果必须的话;

This sounds like a horrible idea, but, well, if you must;

routes.MapRoute(
    "ReallyBadIdea",
    "{*url}",
    new { controller = "MyFatController", action = "MySingleAction" }
    );

这会将所有内容路由到单个控制器中的单个操作.如果您想要更多,还有 {*path} 和其他 URL 模式灵活性.

This routes everything to a single action in a single controller. There's also {*path} and other URL patterns should you want slightly more flexibility.

这篇关于ASP.NET MVC:许多路由->总是只有一个控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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