Skip to content

Instantly share code, notes, and snippets.

@NickJosevski
Created January 4, 2012 11:42
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save NickJosevski/1559695 to your computer and use it in GitHub Desktop.
Save NickJosevski/1559695 to your computer and use it in GitHub Desktop.
Playing with Routes
routes.MapRoute("Shortcuts",
"{whereToGo}",
new
{
controller = "TheRouter",
action = "TryRoute"
});
public class TheRouterController : Controller
{
//
// GET: /TheRouter/
public ActionResult TryRoute(String whereToGo)
{
var actualPath = "";
switch (whereToGo)
{
case "a":
actualPath = @"http://en.wikipedia.org/wiki/Main_Page";
break;
case "DC":
actualPath = @"http://marketplace.xbox.com/en-AU/Product/Dance-Central-2/66acd000-77fe-1000-9115-d802373307d2";
break;
case "FNinja":
actualPath =
@"http://marketplace.xbox.com/en-AU/Product/Fruit-Ninja-Kinect/66acd000-77fe-1000-9115-d80258410b79";
break;
default:
return RedirectSafely(whereToGo);
}
return Redirect(actualPath);
}
private ActionResult RedirectSafely(string whereToGo)
{
try
{
return RedirectToRoute("Default", new { controller = whereToGo } );
}
catch (Exception ex)
{
return RedirectToAction("Index", "Home");
}
}
/*public ActionResult Index()
{
return View();
}*/
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment