且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

ASP.NET MVC单向路由

更新时间:2022-11-26 14:33:48

是的,您可以执行所要求的操作。您只需创建从当前路径继承的自己的路由,并覆盖 GetVirtualPath 以始终返回null。这样就不会执行任何操作查找,但是URL仍将充当到您的操作/控制器的路由映射。

Yes you can do what you are asking. You would just create your own route that inherited from the current one and override GetVirtualPath to always return null. This way no Action lookup would be done, but the URL would still function as a routing mapping to your action/controller.

此外,发生的事情是' URL重写,因为您使用路由在应用程序中定义了端点。换句话说,就是API。因此,不会进行任何重写。将路由和您的操作/控制器之间的关系看作是Web的公共定义的名称空间。就像命名空间一样,您正在应用程序中定义一个特定的位置,可以在其中找到您的动作/控制器。

Also by the way, what is happening isn't URL Rewriting, because you using the Routes to define endpoints in to your application. Or in other words an API. So no rewriting is taking place. Think of the relationship between routes and your action/controller as more of a publically defined namespace for the web. Just like a namespace you are defining a specific spot in your application where your action/controller can be found.