【问题标题】:MVC Routing - Redirect Unknown RoutesMVC 路由 - 重定向未知路由
【发布时间】:2020-05-26 10:04:42
【问题描述】:

我们有一个处理多个客户的网站,它在过去已设置为根据路线数据值“客户”为该客户配置页面 下面的路线是一个例子:

routes.MapRoute("Customer", "{customer}", New With {.controller = "home", .customer = UrlParameter.Optional, .action = "Index"})

这意味着以下 URL 的行为如下: mysite.com/customer1 > mysite.com/customer1/index mysite.com/customer2 > mysite.com/customer2/index

我想将路由数据值“customer”不等于“customer1”或“customer2”的任何请求重定向回根“mysite.com”。

有没有办法配置路由表,以便只有“customer1”或“customer2”是有效路径,而其他路径则转到不同的 url?

提前致谢。

【问题讨论】:

    标签: asp.net-mvc routes


    【解决方案1】:

    在处理客户操作的控制器中,如果在 URL 参数中找不到客户,则返回重定向

    【讨论】:

    • 这就是我的想法,我可能会这样做,但是有很多动作,所以我认为最好在一个地方而不是每个动作中都这样做。
    猜你喜欢
    • 2014-12-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-06-23
    • 2012-07-06
    • 2011-08-19
    • 2011-05-07
    相关资源
    最近更新 更多