2011-08-23 25 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

相关问题