代码之家  ›  专栏  ›  技术社区  ›  Vojtěch Dohnal

HTTP错误400正在运行ASP.NET核心2.1 React应用

  •  0
  • Vojtěch Dohnal  · 技术社区  · 6 年前

    我正在发展ASP.NETVisual Studio 2017中的核心2.1 React应用程序。今天我想从Visual Studio启动一个以前可以启动的应用程序,但出现了错误:

    错误请求-无效主机名HTTP错误400。请求主机名为 无效。

    在VS 2017的启动菜单中,我从IIS Express切换到project exe之后,我看到了以下消息:

    整个日志如下所示:

    info: Microsoft.AspNetCore.DataProtection.KeyManagement.XmlKeyManager[0]
          User profile is available. Using 'C:\Users\vdohnal\AppData\Local\ASP.NET\DataProtection-Keys' as key repository and Windows DPAPI to encrypt keys at rest.
    info: Microsoft.AspNetCore.SpaServices[0]
          Starting create-react-app server on port 50222...
    Hosting environment: Development
    Content root path: C:\VSTS\Dixie\Dixie
    Now listening on: https://localhost:5001
    Now listening on: http://localhost:5000
    Application started. Press Ctrl+C to shut down.
    dbug: HttpsConnectionAdapter[1]
          Failed to authenticate HTTPS connection.
    System.IO.IOException: Authentication failed because the remote party has closed the transport stream.
       at System.Net.Security.SslState.StartReadFrame(Byte[] buffer, Int32 readBytes, AsyncProtocolRequest asyncRequest)
       at System.Net.Security.SslState.StartReceiveBlob(Byte[] buffer, AsyncProtocolRequest asyncRequest)
       at System.Net.Security.SslState.ForceAuthentication(Boolean receiveFirst, Byte[] buffer, AsyncProtocolRequest asyncRequest)
       at System.Net.Security.SslState.ProcessAuthentication(LazyAsyncResult lazyResult)
       at System.Net.Security.SslStream.BeginAuthenticateAsServer(SslServerAuthenticationOptions sslServerAuthenticationOptions, CancellationToken cancellationToken, AsyncCallback asyncCallback, Object asyncState)
       at System.Net.Security.SslStream.<>c.<AuthenticateAsServerAsync>b__51_0(SslServerAuthenticationOptions arg1, CancellationToken arg2, AsyncCallback callback, Object state)
       at System.Threading.Tasks.TaskFactory`1.FromAsyncImpl[TArg1,TArg2](Func`5 beginMethod, Func`2 endFunction, Action`1 endAction, TArg1 arg1, TArg2 arg2, Object state, TaskCreationOptions creationOptions)
       at System.Threading.Tasks.TaskFactory.FromAsync[TArg1,TArg2](Func`5 beginMethod, Action`1 endMethod, TArg1 arg1, TArg2 arg2, Object state, TaskCreationOptions creationOptions)
       at System.Threading.Tasks.TaskFactory.FromAsync[TArg1,TArg2](Func`5 beginMethod, Action`1 endMethod, TArg1 arg1, TArg2 arg2, Object state)
       at System.Net.Security.SslStream.AuthenticateAsServerAsync(SslServerAuthenticationOptions sslServerAuthenticationOptions, CancellationToken cancellationToken)
       at Microsoft.AspNetCore.Server.Kestrel.Https.Internal.HttpsConnectionAdapter.InnerOnConnectionAsync(ConnectionAdapterContext context)
    info: Microsoft.AspNetCore.Hosting.Internal.WebHost[1]
          Request starting HTTP/1.1 GET https://localhost:5001/
    info: Microsoft.AspNetCore.HostFiltering.HostFilteringMiddleware[0]
          The host 'localhost:5001' does not match an allowed host.
    info: Microsoft.AspNetCore.Hosting.Internal.WebHost[2]
          Request finished in 55.2128ms 400 text/html
    info: Microsoft.AspNetCore.Hosting.Internal.WebHost[1]
          Request starting HTTP/1.1 GET https://localhost:5001/favicon.ico
    info: Microsoft.AspNetCore.Hosting.Internal.WebHost[1]
          Request starting HTTP/1.1 GET https://localhost:5001/favicon.ico
    info: Microsoft.AspNetCore.HostFiltering.HostFilteringMiddleware[0]
          The host 'localhost:5001' does not match an allowed host.
    info: Microsoft.AspNetCore.HostFiltering.HostFilteringMiddleware[0]
          The host 'localhost:5001' does not match an allowed host.
    info: Microsoft.AspNetCore.Hosting.Internal.WebHost[2]
          Request finished in 6.4203ms 400 text/html
    info: Microsoft.AspNetCore.Hosting.Internal.WebHost[2]
          Request finished in 8.9463ms 400 text/html
    info: Microsoft.AspNetCore.SpaServices[0]
          > Dixie@0.1.0 start C:\VSTS\Dixie\Dixie\ClientApp
    > rimraf ./build && react-scripts start
    
    Starting the development server...
    
    info: Microsoft.AspNetCore.SpaServices[0]
    
    Compiled with warnings.
    
    info: Microsoft.AspNetCore.SpaServices[0]
    
    ./src/components/Home.js
    
    info: Microsoft.AspNetCore.Hosting.Internal.WebHost[1]
          Request starting HTTP/1.1 GET https://localhost:5001/
    info: Microsoft.AspNetCore.HostFiltering.HostFilteringMiddleware[0]
          The host 'localhost:5001' does not match an allowed host.
    info: Microsoft.AspNetCore.Hosting.Internal.WebHost[2]
          Request finished in 3.6957ms 400 text/html
    info: Microsoft.AspNetCore.Hosting.Internal.WebHost[1]
          Request starting HTTP/1.1 GET https://localhost:5001/
    info: Microsoft.AspNetCore.HostFiltering.HostFilteringMiddleware[0]
          The host 'localhost:5001' does not match an allowed host.
    

    我对AVG杀毒软件最近的一些更新产生了怀疑。

    1 回复  |  直到 4 年前
        1
  •  3
  •   Vojtěch Dohnal    6 年前

    哎哟,我和你玩过了 AllowedHosts 前几天我忘记了。在 appsetings.json 文件中有一行应该为localhost读取:

    “AllowedHosts”:“localhost”

        2
  •  0
  •   Dbl    5 年前

    我已通过将此添加到启动设置.json

    "ShutdownTimer.Server": {
      "commandName": "Project",
      "launchBrowser": true,
      "applicationUrl": "https://localhost:5001;http://localhost:5000",
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      }
    },
    "ShutdownTimer.Server (localIP)": {
        "commandName": "Project",
        "launchBrowser": true,
        "applicationUrl": "https://192.168.0.115:5001;http://192.168.0.115:5000",
        "environmentVariables": {
            "ASPNETCORE_ENVIRONMENT": "Development"
        }
    }
    

        3
  •  0
  •   Jeffrey LeCours    4 年前

    今天碰到这个。打开我的心扉appsettings.json文件文件以添加 "AllowedHost": "localhost"

    info: Microsoft.AspNetCore.Hosting.Internal.WebHost[1]
          Request starting HTTP/1.1 GET https://localhost:5001/
    info: Microsoft.AspNetCore.HostFiltering.HostFilteringMiddleware[0]
          The host 'localhost:5001' does not match an allowed host.
    info: Microsoft.AspNetCore.Hosting.Internal.WebHost[2]
          Request finished in 2951.4396ms 400 text/html
    
    info: Microsoft.AspNetCore.Hosting.Internal.WebHost[1]
          Request starting HTTP/1.1 GET https://localhost:5001/
    info: Microsoft.AspNetCore.Routing.EndpointMiddleware[0]
          Executing endpoint 'AsyncControllerTest.Controllers.HomeController.Index (AsyncControllerTest)'
    

    只是让我这样的人知道你没疯。:-)

    推荐文章