Explorar el Código

Modified subdomain routing via url parameter.

pull/29/head
Teknikode hace 6 años
padre
commit
a02e4e15e5
  1. 19
      Teknik/App_Start/SubdomainRoute.cs
  2. 12
      Teknik/Helpers/UrlExtensions.cs

19
Teknik/App_Start/SubdomainRoute.cs

@ -37,7 +37,7 @@ namespace Teknik @@ -37,7 +37,7 @@ namespace Teknik
{
var routeData = base.GetRouteData(httpContext);
if (routeData == null) return null; // Only look at the subdomain if this route matches in the first place.
string subdomain = httpContext.Request.Params["sub"]; // A subdomain specified as a query parameter takes precedence over the hostname.
string subdomain = httpContext.Request.QueryString["sub"]; // A subdomain specified as a query parameter takes precedence over the hostname.
if (subdomain == null)
{
string host = httpContext.Request.Headers["Host"];
@ -52,8 +52,19 @@ namespace Teknik @@ -52,8 +52,19 @@ namespace Teknik
subdomain = string.Empty;
}
}
else
{
if (routeData.Values["sub"] == null)
{
routeData.Values["sub"] = subdomain;
}
else
{
subdomain = routeData.Values["sub"].ToString();
}
}
routeData.Values["sub"] = subdomain;
//routeData.Values["sub"] = subdomain;
if (subDomain == subdomain)
{
return routeData;
@ -63,8 +74,8 @@ namespace Teknik @@ -63,8 +74,8 @@ namespace Teknik
public override VirtualPathData GetVirtualPath(RequestContext requestContext, RouteValueDictionary values)
{
object subdomainParam = requestContext.HttpContext.Request.Params["sub"];
if (subdomainParam != null)
object subdomainParam = requestContext.HttpContext.Request.QueryString["sub"];
if (subdomainParam != null && values["sub"] == null)
values["sub"] = subdomainParam;
return base.GetVirtualPath(requestContext, values); // we now have the route based on subdomain
}

12
Teknik/Helpers/UrlExtensions.cs

@ -40,20 +40,28 @@ namespace Teknik @@ -40,20 +40,28 @@ namespace Teknik
}
// Grab the sub from parameters if it exists
string subParam = url.RequestContext.HttpContext.Request.Params["sub"]; // A subdomain specified as a query parameter takes precedence over the hostname.
string subParam = url.RequestContext.HttpContext.Request.QueryString["sub"]; // A subdomain specified as a query parameter takes precedence over the hostname.
// If the param is not being used, we will use the curSub
if (string.IsNullOrEmpty(subParam))
{
// If we are in dev, we need to keep it in dev
firstSub = (curSub == "dev") ? "dev" : sub;
rightUrl = url.Action(action, controller, routeValues);
}
else
{
// sub within param will always be on the dev subdomain
firstSub = (string.IsNullOrEmpty(curSub)) ? string.Empty : "dev";
if (subParam != "dev")
{
rightUrl = url.Action(action, controller, Utility.Merge(new { sub = sub }, routeValues));
}
else
{
rightUrl = url.Action(action, controller, routeValues);
}
}
rightUrl = url.Action(action, controller, routeValues);
domain = (string.IsNullOrEmpty(firstSub)) ? domain : firstSub + "." + domain;

Cargando…
Cancelar
Guardar