[英].Request.Url.Host doesn't show subdomain
我在applicationhost.config中設置了綁定,以使子域適用於我在本地測試的項目。
<bindings>
<binding protocol="http" bindingInformation="*:62914:localhost" />
<binding protocol="http" bindingInformation="*:62914:de.localhost" />
</bindings>
我可以通過子域訪問該站點,並看到它在localhost上運行。
我希望能夠讀取子域。 我用下面的代碼。
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
在字符串中沒有子域。
如何閱讀子域名?
使用Request.Url.AbsoluteUri,您可以獲得包括子域在內的完整URL。 這里介紹完整的方法。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.