chum of chance
chum of chance

Reputation: 6300

ASP.NET MVC, email address as parameter breaking routes

I have the following actionresult:

public ActionResult Confirmation(string emailAddress)

When I try to access it:

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

I get this:

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]

What gives why isn't it looking for the correct view? If I go to "/SignUp/" it correctly shows me the index, along with the other ActionResults working correctly. Why does an address break it?

Upvotes: 0

Views: 1578

Answers (2)

davecoulter
davecoulter

Reputation: 1826

Have you tried registering the route in the global.asax.cs?

Something like:

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

Upvotes: 0

RPM1984
RPM1984

Reputation: 73113

You shouldn't be passing that info in the URL anyway.

If this is kind of a "Confirmation" page from a signup, you could pass another identifier, e.g the UserId that has just been created, then fetch it from the repo.

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);
}

So your URL would be (without a specialized route)

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

Putting user's email addresses in the URL is asking for them to be spammed.

Upvotes: 2

Related Questions