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

查看:135
本文介绍了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 /约,/产品/ 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" }
    );

这一切的路线到单个操作在一个单一的控制器。还有{*}的路径,你应该要稍微灵活其他 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天全站免登陆