我的MVC Web應用程序生成可包含任何字符(%,+,/等)的激活鏈接。我URL編碼字符串,並生成鏈接:使用ASP.NET MVC處理URL編碼的參數
new UrlHelper(HttpContext.Current.Request.RequestContext)
.RouteUrl("AccountActivation",
new { id = HttpContext.Current.Server.UrlEncode(activationString) };
再加入域,它看起來像:然後
http://localhost/AccountActivation/asdlkj223%25asd%2Basw3fgasdme
URL傳遞給用戶。
在這種情況下,這條路線是:
routes.MapRoute(
"ActivateAccount",
"AccountActivation/{id}",
new { controller = "Account", action = "Activate", id = ""});
這似乎沒什麼問題,但ASP.NET開發服務器和IIS給我HTTP錯誤400 - 錯誤的請求。這意味着我無法看到該網址存在問題。
當在路由描述擺脫{ID}的(我也試過{* ID}沒有成功):
routes.MapRoute(
"ActivateAccount",
"AccountActivation",
new { controller = "Account", action = "Activate"});
的URL看起來像:
http://AccountActivation?id=asdlkj223%25asd%2Basw3fgasdme
,他們工作很好...
我雖然這兩種方法做的事情完全一樣。他們有什麼區別?是MVC引擎爲我執行更多還是我錯過了URL編碼的東西。
什麼是您的激活作用是什麼樣子?日誌中是否有例外,提供有關基礎錯誤的更多信息? – chris 2012-01-09 16:11:42