如何在 ASP.NET MVC 中设置通用控制器?
我知道这可能不符合 MVC 的真正精神,但我只想有一个全局控制器,无论 url 是什么样子,它总是会被调用。 例如,它可以是:
http:// /myserver.com/anything/at/all/here.fun?happy=yes&sad=no#yippie
...我希望将其传递到我的单个控制器。 我打算以编程方式获取路径并自己处理它——所以换句话说,我根本不需要任何路由。
我已经打开了 global.asax 文件并找到了注册路由的位置,但我只是不知道在 MapRoute 中为“url”参数添加什么:
routes.MapRoute( "Global", "", new { controller = "Global", action = "Index" } );
这(带有空白“url”)对于默认值效果很好'/' 的路径,但如果我将其更改为任何内容,当我希望它处理任何 url 时,我会找不到文件。 我也尝试过“*”等,但没有用。
我找不到任何关于 url 参数采用的格式的明确参考。
I know it's not perhaps in the true spirit of MVC, but I just want to have a single global controller that always gets called no matter what the url looks like. For example, it could be:
http://myserver.com/anything/at/all/here.fun?happy=yes&sad=no#yippie
...and I want that to be passed to my single controller. I intend to obtain the path programmatically and handle it myself--so in other words, I don't really want any routing at all.
I've opened up the global.asax file and found where routes are registered, but I just don't know what to put for the 'url' parameter in MapRoute:
routes.MapRoute( "Global", "", new { controller = "Global", action = "Index" } );
This (with the blank 'url') works fine for the default path of '/', but if I change it to anything I get a file not found, when I want it to handle any url. I also tried "*", etc. but that didn't work.
I couldn't find any definitive reference to the format that the url parameter takes.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
怎么样:
来自这个问题
How about:
from this question
你还没有去掉默认的吧? 你需要保留那个。 也许尝试:
You have not removed the default have you? You need to keep that one. Maybe try: