6

Ich habe eine Route wie folgt:ASP.NET-Routing mit einem ungleich Zwang

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

Diese für alle Benutzer funktioniert gut aber Ich habe eine Situation, wo ich eine Aktion für getmoreactivity treffen wollen. Also möchte ich diese Einschränkung machen, wenn der Benutzername NICHT getmoreactivity ist. Es funktioniert einfach nicht.

Ich habe auf dem RouteDebugger fest und versuchte @ "[^ (getmoreactivity)]" @ "^ (getmoreactivity)" @ "getmoreactivity" @ "[^ getmoreactivity]". Nun, ich habe unzählige Dinge ausprobiert, aber keines löst mein Problem.

Wie zur Hölle setzen Sie ein NOT Constraint auf ein ganzes Wort?

Antwort

16

Versuch:

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

?! ist ein Look-Ahead: http://www.regular-expressions.info/refadv.html

......

+1

siehe auch http://stackoverflow.com/questions/406230/regular-expression- to-match-line-das-enthält-nicht-ein-Wort für weitere Details –

Verwandte Themen