Created
January 4, 2012 11:42
-
-
Save NickJosevski/1559695 to your computer and use it in GitHub Desktop.
Playing with Routes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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