private string PrefixSubDomain(string subDomain)
{
string[] parts = Request.Url.ToString().Split('/');
StringBuilder newPath = new StringBuilder(parts[0]);
for (int i = 1; i < parts.Length; i++)
{
if (i == 2)
{
newPath.AppendFormat("/{0}", subDomain);
if (subDomain.EndsWith("."))
{
newPath.Append(parts[i]);
}
else
{
newPath.AppendFormat(".{0}", parts[i]);
}
}
else
{
newPath.AppendFormat("/{0}", (string.IsNullOrEmpty(parts[i]) ? "" : parts[i]));
}
}
return newPath.ToString();
}
Sorry about all the revisions. I was fixing as I thought of stuff.