如何测试开发机器上的子域? abc.localhost [英] How to test subdomains on a development machine? abc.localhost
问题描述
我想开发一个asp.net网站与多个子域。我是新来的,一般特别网站和asp.net。然而,似乎通配符子域是正确设置使用DNS条目和Web服务器配置的组合 - 这是不会我的开发机器上发生。所以,我是手动插入在我的窗口项的 hosts文件
I am trying to develop an asp.net site with multiple subdomains. I am new to web sites in general, and asp.net in particular. However, it seems that wildcard subdomains are properly setup with a combination of dns entries and web server configuration - which isn't going to happen on my development machine. Therefore I'm manually inserting entries in my windows hosts file:
127.0.0.1 localhost
127.0.0.1 abc.localhost
127.0.0.1 xyz.localhost
然而,当我试图询问的 Request.Url 属性没有子待观察。例如,如果我打 HTTP://abc.localhost:1660 /
在浏览器中,我得到的http://本地主机:1660 /
从 Request.Uri.ToString()
;在 ABC
只是走了?
However, when I try to interrogate the Request.Url property there is no subdomain to be seen. For example, if I hit http://abc.localhost:1660/
in the browser I get http://localhost:1660/
from Request.Uri.ToString()
; the abc
is just gone?!
我不知道为什么hosts文件是这样的,但有我可以用它来获取子域进入我的本地Web应用程序中任何其他方法?谢谢大家。
I don't know why the hosts file works like this, but is there any other method I can use to get subdomains into my local web application? Thank you all.
请注意,我只使用内置asp.net开发服务器,而不是一个完整的IIS服务器。 (我不能访问完整的IIS本周末,但我还是想知道,如果这将有助于。)
Note that I'm only using the built-in asp.net development server rather than a full iis server. (I can't get access to a full IIS this weekend, but I would still like to know if that would help.)
推荐答案
您可以用二级域名使用完整的请求的域的 Request.Headers [HOST] 的。下面是返回当前请求的子域的简单方法。这种方法也假定你有一个.COM,。NET等域名,就像真正的Web之后。所以,你要改变你的HOSTS文件,包括localhost.com,abc.localhost.com等。
You can get the requested domain with Subdomain intact by using "Request.Headers["HOST"]". Here's a simple method that returns the Subdomain of the current request. This method also assumes that you have a ".COM", ".NET", etc. after the domain just like the real web. So you'll want to change your HOSTS file to include "localhost.com", "abc.localhost.com", etc.
public string subdomain()
{
string host = Request.Headers["HOST"];
if (!string.IsNullOrEmpty(host))
{
var parts = host.Split('.');
if (parts.Length > 2)
{
return parts[0];
}
}
return string.Empty;
}
我正在寻找在这个非常的事情,这里有一篇文章,是实际帮助我弄清楚了这一点:
<一href=\"https://web.archive.org/web/20090813174916/http://blogs.securancy.com/post/ASPNET-MVC-Subdomain-Routing.aspx\" rel=\"nofollow\">https://web.archive.org/web/20090813174916/http://blogs.securancy.com/post/ASPNET-MVC-Subdomain-Routing.aspx
这篇关于如何测试开发机器上的子域? abc.localhost的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!