9

私はそのようなルートを持っています:

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

これはすべてのユーザーに対して正常に機能します、getmoreactivityのアクションを実行したい状況があります。したがって、ユーザー名がgetmoreactivityではない場合にこの制約を適用したいと思います。しかし、それは機能していません。

RouteDebuggerを使い続けて、@ "[^(getmoreactivity)]" @ "^^(getmoreactivity)" @ "^ getmoreactivity" @"[^getmoreactivity]"を試しました。さて、私は無数のことを試みましたが、どれも私の問題を解決しません。

単語全体にNOT制約をどのように適用しますか?

4

1 に答える 1

20

試す:

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

?!先読みです: http://www.regular-expressions.info/refadv.html

……

于 2010-12-10T11:41:57.357 に答える