SSW Foursquare

Do you use the URL as a navigation aid (aka redirect if URL is incorrect)?

Last updated by Brady Stroud [SSW] 8 months ago.See history

Figure: Watch the URL working as a navigation aid

MVC gives us great URLs, but you need to help users navigate via the URL. If the user changes a URL, and the route parameters no longer match, you should correct them with a redirect.

public ActionResult Edit(string employeename, int id)
{
    var model = _repository.GetEmployee(id);

    // check for a parameter match and redirect if incorrect
    if (string.IsNullOrEmpty(employeename) || employeename != model.EmployeeName)
    {
        return RedirectToAction(
            "Edit", new { employeename = model.EmployeeName, id });
    }

    return View(model);
}

Figure: Good example - The comment says it all Wordpress and Stack Overflow have URL formats that do this very well

Figure: Good example - If the "settimeout-or-setinterval" part of th eURL changes, the page will redirect to the correct location


Adam Cogan
Damian Brady
We open source.Loving SSW Rules? Star us on GitHub. Star
Stand by... we're migrating this site to TinaCMS