Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/264.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# localhost上的子域发出错误请求-无效主机名错误_C#_Asp.net_Asp.net Mvc_Subdomain_Asp.net Mvc Routing - Fatal编程技术网

C# localhost上的子域发出错误请求-无效主机名错误

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://

我正在使用MVC。我想用IIS在本地主机上测试子域。我创建子域所做的是:

  • 我在windows主机文件中添加了一行

    127.0.0.1       localhost
    127.0.0.1       abc.localhost
    ::1             localhost
    
  • 我将
    applicationhost.config
    编辑为:

  • 我的索引方法是:

    公共字符串索引()
    {
    if(subdomainName==null)
    {
    返回“无子域”;
    }
    返回子域名;
    }

  • 现在url
    http://localhost:59322/
    工作正常。但是url
    http://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>