6

我有一个路线,像这样:ASP.NET路由具有不等于约束

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

这为所有用户我有,我想打的getmoreactivity动作的情况下正常工作。所以我想让这个约束来说明何时用户名不是getmore活动。这只是不工作。

我一直坚持RouteDebugger,并试图@“[^(getmoreactivity)]”@“^^(getmoreactivity)”@“^ getmoreactivity”@“[^ getmoreactivity]”。那么我已经尝试了无数的事情,但没有解决我的问题。

你到底是怎么把整个单词放在一个NOT约束下的?

回答

16

尝试:

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

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

......

+1

也看到http://stackoverflow.com/questions/406230/regular-expression-以便找到更多细节的匹配行,不包含单词 – 2015-09-28 01:16:27