C# localhost上的子域发出错误请求-无效主机名错误
我正在使用MVC。我想用IIS在本地主机上测试子域。我创建子域所做的是:C# localhost上的子域发出错误请求-无效主机名错误,c#,asp.net,asp.net-mvc,subdomain,asp.net-mvc-routing,C#,Asp.net,Asp.net Mvc,Subdomain,Asp.net Mvc Routing,我正在使用MVC。我想用IIS在本地主机上测试子域。我创建子域所做的是: 我在windows主机文件中添加了一行 127.0.0.1 localhost 127.0.0.1 abc.localhost ::1 localhost 我将applicationhost.config编辑为: 我的索引方法是: 公共字符串索引() { if(subdomainName==null) { 返回“无子域”; } 返回子域名; } 现在urlhttp://
127.0.0.1 localhost
127.0.0.1 abc.localhost
::1 localhost
applicationhost.config
编辑为:公共字符串索引()
{
if(subdomainName==null)
{
返回“无子域”;
}
返回子域名;
}
http://localhost:59322/
工作正常。但是urlhttp://abc.localhost:59322/
给出了错误信息
错误的请求-无效的主机名
HTTP错误400。请求主机名无效
我做错了什么。为什么子域不工作?我知道已经很晚了,但为了供其他人参考,只需添加
applicationhost.config
:
<bindings>
<binding protocol="http" bindingInformation="*:59322:" />
</bindings>
如果我的问题不清楚,请告诉我。我3年前问过这个问题,今天又遇到了同样的问题,我还尝试以管理员身份运行vs,有人知道吗?
public string subdomainName
{
get
{
string s = Request.Url.Host;
var index = s.IndexOf(".");
if (index < 0)
{
return null;
}
var sub = s.Split('.')[0];
if (sub == "www" || sub == "localhsot")
{
return null;
}
return sub;
}
}
<bindings>
<binding protocol="http" bindingInformation="*:59322:" />
</bindings>