【问题标题】:ASP.NET routing with a NOT equal to constraint具有不等于约束的 ASP.NET 路由
【发布时间】:2011-05-23 10:19:28
【问题描述】:

我有这样的路线:

routes.MapRoute
    (
    "Profile",
    "profile/{username}",
    new { controller = "Profile", action = "Index" },
    new { username = @"^(getmoreactivity)" }
    );

这对所有用户都很好但是我有一种情况,我想为 getmoreactivity 执行操作。所以我想让这个约束说明用户名何时不是 getmoreactivity。但它只是不起作用。

我坚持使用 RouteDebugger 并尝试了 @"[^(getmoreactivity)]" @"^^(getmoreactivity)" @"^getmoreactivity" @"[^getmoreactivity]"。好吧,我尝试了无数的事情,但没有一个能解决我的问题。

你到底是怎么对整个单词加上 NOT 约束的?

【问题讨论】:

    标签: asp.net asp.net-mvc routing asp.net-mvc-routing asp.net-routing


    【解决方案1】:

    尝试:

    routes.MapRoute 
    ( 
    "Profile", 
    "profile/{username}", 
    new { controller = "Profile", action = "Index" }, 
    new { username = "(?!getmoreactivity).*" } 
    ); 
    

    ?! 是一个前瞻:http://www.regular-expressions.info/refadv.html

    ......

    【讨论】:

    猜你喜欢
    • 2013-12-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-05-30
    • 1970-01-01
    • 2019-02-10
    • 2011-06-01
    相关资源
    最近更新 更多