I am creating an application in ASP.net where each user will have their own profile that they can share with others.
the default address for their profile will be:
www.domain.com/User/Profile/[UserID]
when they specify a vanity URL, someone can enter
www.domain.com/User/Profile/[Vanity]
and be directed to the same page. The profile page works with only one function taking in a UserID with the following function in the controller:
public ActionResult Profile(int id)
{
ppUser viewerChoice = DB.User_GetUserByPersonID(id);
return View(viewerChoice);
}
However, when I add another that takes a string
public ActionResult Profile(string vanity)
{
ppUser viewerChoice = DB.User_GetUserByVanity(vanity);
return View(viewerChoice);
}
This causes an AmbiguousMatch Exception. How would I go about making sure that it calls the correct function?
You have few options.
I would be very careful with you approach (same actions, different parameters) as there is a risk of user choosing int (same format as user id) for a vanity URL. How would you resolve such conflict?