0

I've setup the binding in my applicationhost.config to have subdomain working for my project which I test locally.

 <bindings>
    <binding protocol="http" bindingInformation="*:62914:localhost" />
    <binding protocol="http" bindingInformation="*:62914:de.localhost" />
 </bindings>

I can access the site via the subdomain and see it running on localhost.

I want to be able to read the subdomain. I used the following code.

 var host = HttpContext.Current.Request.Url.Host;
 var index = host.IndexOf(".");
 string[] segments = HttpContext.Current.Request.Url.PathAndQuery.Split('/');

  if (index < 0)
    return null;

  var subdomain = host.Substring(0, index);

  return subdomain;

The problem is that HttpContext.CurrentRequest.Url doesn't have the subdomain in the string.

How can I read the subdomain?

Liron Harel
  • 10,819
  • 26
  • 118
  • 217

1 Answers1

0

with Request.Url.AbsoluteUri you can get complete URL including subdomain. Complete methods described here.

Alia
  • 28
  • 5