2011-08-23 87 views
0

我有以下的ActionResult:ASP.NET MVC,電子郵件地址作爲參數突破路線

公衆的ActionResult確認(串)移轉

當我嘗試訪問它:

http://localhost:8080/Signup/Confirmation?emailAddress=test%40test.com

我得到這個:

The view '[email protected]' or its master was not found or no view engine supports the searched locations. The following locations were searched: 
~/Views/Signup/[email protected] 
~/Views/Signup/[email protected] 

爲什麼不是它尋找正確的觀點?如果我轉到「/ SignUp /」,它會正確顯示索引,以及其他ActionResults正常工作。爲什麼地址會打破它?

+0

不應該是http:// localhost:8080 /註冊/確認/測試%40test.com –

+0

我相信這是典型的「。」。問題。 http://stackoverflow.com/questions/5732507/asp-net-mvc-2-issue-dot-in-route –

回答

0

您是否嘗試過在global.asax.cs中註冊路由?

喜歡的東西:

routes.Add("confirmation", 
    new Route("Signup/Confirmation/{email}", 
    new RouteValueDictionary(new { controller = "Signup", action = "Confirmation", email = UrlParameter.Optional }), 
    new MvcRouteHandler()) 
); 
2

你不應該反正通過URL中的信息。

如果這是註冊時的「確認」頁面,您可以傳遞另一個標識符,例如剛剛創建的UserId,然後從回購中獲取它。

E.g:

[HttpPost] 
public ActionResult Signup(SignupViewModel model) 
{ 
    //.. code to save.. etc 

    return RedirectToAction("Confirmation", new { id = newUser.UserId }); 
} 

[HttpGet] 
public ActionResult Confirmation(int id) 
{ 
    var user = repo.FindById(id); 
    // map to model, etc... 
    return View(model); 
} 

所以您的網址是(沒有專門的路線)

http://localhost:8080/Signup/Confirmation?id=123213 

把用戶的電子郵件地址的網址是要求對它們進行垃圾郵件。

+0

我不確定用戶會被垃圾郵件。在抓取網站時,垃圾郵件發送者如何能夠通過URL讀取任何其他用戶的電子郵件地址?我想中間的人可能會攔截請求並捕獲url,但這似乎是獲取電子郵件地址的一種非常密集的方式。 –

+0

@Mystere人 - 它的可能。讓我們不要進入它,但一般來說,總是更好*不*要在可能的情況下**傳遞這些信息**,在這種情況下肯定是可能的。沒有添加任何值可在URL中傳遞電子郵件。 – RPM1984

相關問題