Last active
September 6, 2016 18:14
-
-
Save rymoore99/6046f3642d00ce370eb1 to your computer and use it in GitHub Desktop.
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
public class CustomSiteRoutes : RouteBase | |
{ | |
public override RouteData GetRouteData(HttpContextBase httpContext) | |
{ | |
if (httpContext.Request.Url.Host.Contains("site2.com")) | |
{ | |
string url = httpContext.Request.AppRelativeCurrentExecutionFilePath; | |
string controllername = "Home"; | |
string actionname = "Index"; | |
// let's mess with the URLs - if not in this list, custom sites won't | |
// handle them differently than Athletix.us | |
var urlsToHandle = new List<string> | |
{ | |
"~/", | |
"~/about", | |
"~/contact", | |
"~/join" | |
}; | |
if (urlsToHandle.Contains(url)) | |
{ | |
var routeHandler = new MvcRouteHandler(); | |
var currentRoute = new Route("{controller}/{action}", routeHandler); | |
var routeData = new RouteData(currentRoute, routeHandler); | |
// determine, beased on the URL, which controller / action to send the request to | |
switch (url) | |
{ | |
case "~/": | |
controllername = "CustomSite"; | |
actionname = "Home"; | |
break; | |
case "~/about": | |
controllername = "CustomSite"; | |
actionname = "Page"; | |
routeData.Values.Add("location", Context.Current.CustomSite.AboutUsPageSnippet); | |
break; | |
case "~/contact": | |
controllername = "CustomSite"; | |
actionname = "Page"; | |
routeData.Values.Add("location", Context.Current.CustomSite.ContactUsPageSnippet); | |
break; | |
case "~/join": | |
controllername = "CustomSite"; | |
actionname = "Page"; | |
routeData.Values.Add("location", Context.Current.CustomSite.RegisterPageSnippet); | |
break; | |
} | |
// controller / action set dynamically | |
routeData.Values["controller"] = controllername; | |
routeData.Values.Add("action", actionname); | |
// return the route, or null to have it passed to the next routing engine in the list | |
return routeData; | |
} | |
} | |
return null; | |
} | |
public override VirtualPathData GetVirtualPath(RequestContext requestContext, RouteValueDictionary values) | |
{ | |
//implement this to return url's for routes, or null to just pass it on | |
return null; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment