ASP.Net MVC:使用路由重写
我想将以下 URI: 映射
/admin/controller/action/id
到以下内容:
Controller -> Controller
Action -> Admin_Action
例如:
/admin/Users/Create
Controller -> Users
Action -> Admin_Create
/admin/Users/Delete/1
Controller -> Users
Action -> Admin_Delete(1)
我可以使用路由规则实现这一点吗?
I want to map the following URI:
/admin/controller/action/id
to the following:
Controller -> Controller
Action -> Admin_Action
For example:
/admin/Users/Create
Controller -> Users
Action -> Admin_Create
/admin/Users/Delete/1
Controller -> Users
Action -> Admin_Delete(1)
Can I achieve that using routing rules?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我认为以下路线映射应该有效......
I think the following route mapping should work ...
使用这个:
但是如果你愿意你也可以这样做
www.example.com/admin/
更新
Use this:
But if you want you can also do
www.example.com/admin/
Update
您可以使用
RouteHandler
在操作前面添加名称,正如我在 这个答案。如果您创建一个名为
AdminHandler
的 RouteHandler 来在您的操作前面添加“Admin_`,则您可以按如下方式定义您的路线:但是,我同意 brodie 的观点,您应该将所有管理操作放在一个单独的区域中,因为它是更好的设计,并且使安全性和维护更容易。
You can prepend names to actions using a
RouteHandler
, as I describe in this answer.If you create a RouteHandler named
AdminHandler
to prepend "Admin_` to your actions, you can then define your route as follows:However, I agree with brodie that you should place all admin actions in a separate Area, as it is a better design, and makes security and maintenance easier.