Asp.net

具有不等於約束的 ASP.NET 路由

  • April 11, 2011

我有這樣的路線:

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

這對所有使用者都適用,我有一種情況,我想為 getmoreactivity 執行操作。所以我想用這個約束來說明使用者名何時不是 getmoreactivity。它只是不工作。

我堅持使用 RouteDebugger 並嘗試了@"

$$ ^(getmoreactivity) $$"@"^^(getmoreactivity)"@"^getmoreactivity"@"$$ ^getmoreactivity $$”。好吧,我嘗試了無數的事情,但沒有一個能解決我的問題。 你到底是如何對整個單詞加上 NOT 約束的?

嘗試:

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

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

……

引用自:https://stackoverflow.com/questions/4408149