我已经在我的applicationhost.config中设置了绑定,以便让子域为我的项目工作,我在本地测试该项目。
<bindings>
<binding protocol="http" bindingInformation="*:62914:localhost" />
<binding protocol="http" bindingInformation="*:62914:de.localhost" />
</bindings>我可以通过子域访问该站点,并看到它在本地主机上运行。
我希望能够读取子域名。我使用了以下代码。
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;问题是HttpContext.CurrentRequest.Url在字符串中没有子域。
如何读取子域名?
发布于 2018-09-04 15:18:08
使用Request.Url.AbsoluteUri,你可以获得完整的网址,包括子域。完整的方法描述了here。
https://stackoverflow.com/questions/52152325
复制相似问题