ASP.Net MVC控制器命名空间阵列 [英] ASP.Net MVC Controller Namespace array

查看:145
本文介绍了ASP.Net MVC控制器命名空间阵列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我注意到,图路线扩展包括接受字符串[]参数,它被称为命名空间过载。我读什么谷歌对我有就可以了,按说这是帮助框架找到的地方,否则它不会看的控制器。

I noticed that the MapRoute extension includes an overload that accepts a string[] parameter which is called 'namespaces'. I read what Google had for me on it, and supposedly this is to help the framework find controllers in places it wouldn't otherwise look.

我做了一些扣球,并试图把控制器怪异的位置。我把一个在脚本文件夹;我甚至造成了一辆在单独的程序有一个单独的根命名空间。

I did some spiking, and tried putting controllers in weird locations. I put one in the Scripts folder; I even built one in a separate assembly with a separate root namespace.

没有把点儿的命名空间参数,一切运行良好。如果我把刚才在命名空间参数的命名空间之一,它仍然发现我所有的控制器。我想,也许它会使用该数组名称类似的控制器之间的歧义,但没有任何发生。在MyProj.Controllers一个HomeController的,一个在SomeOtherName.Stuff会发生冲突仍在。

Without putting anyting in the namespaces param, everything worked fine. If I put just one of the namespaces in the namespaces param, it still found all my controllers. I thought maybe it would use that array to disambiguate between similarly named controllers, but that didn't happen either. A HomeController in MyProj.Controllers and one in SomeOtherName.Stuff would collide still.

所以我的问题是,是,参数德precated?或者是它仍然在某种程度上,我还没有辨别用某种方式?

So my question is, is that parameter deprecated? Or is it still used somehow in a way that I have yet to discern?

推荐答案

好了,经过进一步的测试,我想通了,这不是一个过滤器,准确,但它有点是也。我给了,即使你是错的部分,你的回答的功劳。

Ok, so after further testing, I figured out that it is not a filter, exactly, but it kinda is also. I gave you 'answer' credit even though you're partially wrong.

所以,确实如此,毕竟像我想它应该是说,它disambiguates。基本上,逻辑流程是这样的:

So, it does, after all, act like I thought it should which is to say it disambiguates. Basically, the logical flow is something like this:


  • 查找在_cache一个命名空间匹配一个命名空间阵列

    • 如果是的发现,寻找合适的名字的控制器

    • - 如果是这样的发现,其返回

    • - 如果它没有找到,返回搜索其他地方,它通常会看

    因此​​,简而言之,我认为命名空间阵列将有助于消除歧义是正确的。我在这方面的第一次测试失败的原因是,它只做一个完美的比赛,和我做了仅使用根N / S从组件的错误(在其他wordss的,而不是MyRoot MyRoot.Controllers)。

    So, in short, my thought that the namespaces array would serve to disambiguate was correct. The reason my first test in that regard failed is that it only does a perfect match, and I made the mistake of using just the root n/s from the assembly (in other wordss, MyRoot instead of MyRoot.Controllers).

    这是什么东西命名空间允许的话,是有两个不同的命名空间一个HomeController的不同,并与它们匹配根据URL或PARAMS。

    What this namespaces thing allows, then, is to have a HomeController in two different namespaces and match them differently depending on the url or params.

    这篇关于ASP.Net MVC控制器命名空间阵列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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