Browse Source

Modified subdomain routing via url parameter.

tags/2.0.3
Teknikode 5 years ago
parent
commit
a02e4e15e5
2 changed files with 25 additions and 6 deletions
  1. 15
    4
      Teknik/App_Start/SubdomainRoute.cs
  2. 10
    2
      Teknik/Helpers/UrlExtensions.cs

+ 15
- 4
Teknik/App_Start/SubdomainRoute.cs View File

@@ -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
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

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
}

+ 10
- 2
Teknik/Helpers/UrlExtensions.cs View File

@@ -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;


Loading…
Cancel
Save