简体   繁体   English

在 AWS 上部署 blazor 服务器应用程序“错误:如果连接不在‘已连接’State 中,则无法发送数据。” 但适用于本地主机

[英]Deployed blazor server app on AWS “Error: Cannot send data if the connection is not in the 'Connected' State.” But works on local host

I have a blazor server app that is a.Net 5.0 application deployed on AWS using AWS Beanstalk.我有一个 blazor 服务器应用程序,它是使用 AWS Beanstalk 在 AWS 上部署的 .Net 5.0 应用程序。 It is a Single Instance deployment, so I currently can't use load balancing (due to current restrictions given to me).这是一个单实例部署,所以我目前不能使用负载平衡(由于当前给我的限制)。 The deployed environment platform is "IIS 10.0 running on 64bit Windows Server Core 2019/2.6.3".部署的环境平台为“IIS 10.0 running on 64bit Windows Server Core 2019/2.6.3”。 When i run this locally on VS2019 and local iis server, the app works fine.当我在 VS2019 和本地 iis 服务器上本地运行此应用程序时,该应用程序运行良好。 But once deployed, it throws an error in the browser console:但是一旦部署,它会在浏览器控制台中引发错误:

 blazor.server.js:1 [2021-02-19T17:17:03.896Z] Error: Failed to start the transport 'LongPolling': Error e.log @ blazor.server.js:1 blazor.server.js:1 [2021-02-19T17:17:03.897Z] Error: Failed to start the connection: Error: Unable to connect to the server with any of the available transports. ServerSentEvents failed: Error: 'ServerSentEvents' does not support Binary. LongPolling failed: Error e.log @ blazor.server.js:1 blazor.server.js:19 [2021-02-19T17:17:03.897Z] Error: Error: Unable to connect to the server with any of the available transports. ServerSentEvents failed: Error: 'ServerSentEvents' does not support Binary. LongPolling failed: Error e.log @ blazor.server.js:19 blazor.server.js:1 Uncaught (in promise) Error: Cannot send data if the connection is not in the 'Connected' State. at e.send (blazor.server.js:1) at e.sendMessage (blazor.server.js:1) at e.sendWithProtocol (blazor.server.js:1) at blazor.server.js:1 at new Promise (<anonymous>) at e.invoke (blazor.server.js:1) at e.<anonymous> (blazor.server.js:19) at blazor.server.js:19 at Object.next (blazor.server.js:19) at blazor.server.js:19

The app pretty much won't work, like when i press a button it doesnt do what its told, but some hyperlink buttons work though if its forced to load another page.该应用程序几乎无法运行,例如当我按下按钮时,它不会按照它的指示进行操作,但是如果它被迫加载另一个页面,一些超链接按钮仍然可以工作。 I started the blazor app using the blazor server template, so I have the _Imports.razor in the project base location, etc.我使用 blazor 服务器模板启动了 blazor 应用程序,因此我在项目基本位置等中有 _Imports.razor 等。

_host.cshtml _host.cshtml

@page "/"
@namespace Space

@{
  Layout = null;
}

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  <title>UI</title>
  <base href="~/" />
  <link rel="stylesheet" href="css/bootstrap/bootstrap.min.css" />
  <link href="css/site.css" rel="stylesheet" />
  <link href="_content/MatBlazor/dist/matBlazor.css" rel="stylesheet" />

  <!--Blazorise Stuff -->
  <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css" integrity="sha384-9aIt2nRpC12Uk9gS9baDl411NQApFmC26EwAOH8WgZl5MYYxFfc+NcPb1dKGj7Sk" crossorigin="anonymous">
  <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.12.0/css/all.css">
  <link href="_content/Blazorise/blazorise.css" rel="stylesheet" />
  <link href="_content/Blazorise.Bootstrap/blazorise.bootstrap.css" rel="stylesheet" />
</head>

<body>
  <component type="typeof(App)" render-mode="ServerPrerendered" />

  <div id="blazor-error-ui">
    <environment include="Staging,Production">
      An error has occurred. This application may no longer respond until reloaded.
    </environment>
    <environment include="Development">
      An unhandled exception has occurred. See browser dev tools for details.
    </environment>
    <a href="" class="reload">Reload</a>
    <a class="dismiss">🗙</a>
  </div>

  <script src="_framework/blazor.server.js"></script>
  <script src="_content/MatBlazor/dist/matBlazor.js"></script>

  <!-- blazorise stuff  -->
  <script src="https://code.jquery.com/jquery-3.5.1.slim.min.js" integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj" crossorigin="anonymous"></script>
  <script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.0/dist/umd/popper.min.js" integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo" crossorigin="anonymous"></script>
  <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/js/bootstrap.min.js" integrity="sha384-OgVRvuATP1z7JjHLkuOU7Xw704+h835Lr+6QL9UvYjZE3Ipu6Tp75j7Bh/kR0JKI" crossorigin="anonymous"></script>
  <script src="_content/Blazorise/blazorise.js"></script>
  <script src="_content/Blazorise.Bootstrap/blazorise.bootstrap.js"></script>

  <!-- Workarounds -->
  <script src="~/workaround-gradient.js"></script>
</body>
</html>

The startup file启动文件

namespace Space
{
  public class Startup
  {
    public Startup(IConfiguration configuration)
    {
      Configuration = configuration;
    }

    public IConfiguration Configuration { get; }

    // This method gets called by the runtime. Use this method to add services to the container.
    // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
    public void ConfigureServices(IServiceCollection services)
    {
      var connectionString = AwsParameterStore.GetValue(AwsParameters.AwsConnectString) ??
                             Configuration.GetConnectionString("DefaultConnection");

      services.AddDbContext<UiContext>(options =>
          options.UseSqlServer(connectionString));

      ConfigureIdentityStuff(services);

      services.AddServerSideBlazor();
      services.AddScoped<AuthenticationStateProvider, RevalidatingIdentityAuthenticationStateProvider<UiUser>>();
      services.AddDatabaseDeveloperPageExceptionFilter();
      services.AddBlazorDownloadFile();
      services.AddScoped<HttpClient>();
      services.AddBlazorise();
      services.AddBootstrapProviders();
      services.AddFontAwesomeIcons();
      services.AddSignalRCore();
    }

    private void ConfigureIdentityStuff(IServiceCollection services)
    {
      services.AddDefaultIdentity<UiUser>(options =>
       {
         options.SignIn.RequireConfirmedAccount = false;

         // Password settings.
         options.Password.RequireDigit = true;
         options.Password.RequireLowercase = true;
         options.Password.RequireNonAlphanumeric = true;
         options.Password.RequireUppercase = true;
         options.Password.RequiredLength = UserRelatedStaticConstDefaults.DefaultMinimumPasswordLength;
         options.Password.RequiredUniqueChars = 1;

         // Lockout settings.
         options.Lockout.DefaultLockoutTimeSpan = UserRelatedStaticConstDefaults.DefaultLockoutTime;
         options.Lockout.MaxFailedAccessAttempts = 5;
         options.Lockout.AllowedForNewUsers = true;

         // User settings.
         options.User.AllowedUserNameCharacters =
          "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-._@+";
         options.User.RequireUniqueEmail = true;
       })
        .AddRoles<IdentityRole>()
        .AddEntityFrameworkStores<UiContext>();

      services.ConfigureApplicationCookie(options =>
       {
         // Cookie settings
         options.Cookie.HttpOnly = true;
         options.ExpireTimeSpan = TimeSpan.FromMinutes(10);

         options.LoginPath = "/Identity/Account/Login";
         options.AccessDeniedPath = "/Identity/Account/AccessDenied";
         options.SlidingExpiration = true;
       });

      services.TryAddSingleton<IActionContextAccessor, ActionContextAccessor>();
      services.TryAddSingleton<IHttpContextAccessor, HttpContextAccessor>();
      services.AddRazorPages(options =>
      {
        options.Conventions.AuthorizeFolder("/Manage");
      });
    }

    // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
    public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
    {
      Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);

      if (env.IsDevelopment())
      {
        app.UseDeveloperExceptionPage();
        app.UseMigrationsEndPoint();
      }
      else
      {
        app.UseExceptionHandler("/Error");
        // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
        app.UseHsts();
      }

      app.UseHttpsRedirection();
      app.UseStaticFiles();

      app.UseRouting();

      app.ApplicationServices
        .UseBootstrapProviders()
        .UseFontAwesomeIcons();

      app.UseAuthentication();
      app.UseAuthorization();

      app.UseEndpoints(endpoints =>
      {
        endpoints.MapControllers();
        endpoints.MapBlazorHub();
        endpoints.MapRazorPages();
        endpoints.MapFallbackToPage("/_Host");
      });    
    }
  }
}

My _Imports.razor我的 _Imports.razor

@using System.Net.Http
@using Microsoft.AspNetCore.Authorization
@using Microsoft.AspNetCore.Components.Authorization
@using Microsoft.AspNetCore.Components.Forms
@using Microsoft.AspNetCore.Components.Routing
@using Microsoft.AspNetCore.Components.Web
@using Microsoft.AspNetCore.Components.Web.Virtualization
@using Microsoft.JSInterop
@using Space
@using Space.Pages
@using Space.Shared
@using Space.Shared.DataInput
@using Space.Shared.OutputData
@using MatBlazor
@using MatBlazor.Components
@using MatBlazor.Components.MatAutocompleteList
@using ReactiveUI.Blazor
@using Blazorise
@using Blazorise.Components
@attribute [Authorize]

Im not sure whats going on at all.我完全不确定发生了什么。 I tried looking it up but i got nothing following multiple suggestions/answers.我尝试查找它,但在多个建议/答案之后我一无所获。 Could somebody please help!有人可以帮忙吗!

Websockets are needed for Blazor. Blazor 需要 Websocket。 In the windows beanstalk environment, it is apparently disabled by default.在 windows beanstalk 环境中,它显然是默认禁用的。

I enabled them by using this pre-defined config from aws .我通过使用来自 aws 的预定义配置启用了它们。

commands:
  InstallWebsocket:
    command: powershell.exe Install-WindowsFeature -name Web-WebSockets
  EnableWebsocket:
    command: 'C:\windows\system32\inetsrv\appcmd.exe set config "Default Web Site" -section:system.webServer/webSocket /enabled:"True" /receiveBufferLimit:"4194304" /pingInterval:"00:00:10"  /commit:apphost'

Put this config in the .ebextensions folder and things work fine.将此配置放在.ebextensions文件夹中,一切正常。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在Azure上部署的Web无法访问.less文件(错误代码404)。 本地IIS部署可以正常工作 - Deployed web on Azure cannot access a .less file (error code 404). Local IIS deployment works without error 如何为实际连接到我的 Blazor 服务器应用程序的每个客户端分配一个单独的“客户端连接号”? - How can I assign for each client that is actualy connected to my Blazor server app a seperate "Client-connection-number"? 部署 blazor ServerSide 应用程序时服务器上缺少内容 - missing content on server when deployed blazor ServerSide app 将 Blazor 服务器部署到 localhost,默认登录页面 (cshtml) 错误 - Deployed Blazor server to localhost, Default Login page (cshtml) Error Blazor 应用程序不在 IIS 上维护其状态,但在 IISExpress 上运行良好 - Blazor app not maintainintg its state on IIS, but works fine on IISExpress 将 blazor-server 应用程序发布到服务器后无法从 tes.net.binance.vision 获得结果 [在本地主机工作] - after publishing blazor-server app to server cannot get result from testnet.binance.vision [works in localhost] 部署在托管服务器上的代码无法正常工作,但可以在本地工作 - Code not working when deployed on hosting server but works in local 应用程序的SSIS Excel连接无法通过已部署的服务运行 - SSIS Excel connection works from app fails from deployed service 如何清除此Web配置错误,在本地主机上工作正常,但如果我在服务器上上传,则会发生Errror - How To remove This Web config error, It works Fine on local host but if i uploaded on the server then Errror occured 如何在没有互联网连接(仅本地主机)的情况下发送和发送电子邮件? - How to send and email without internet connection,only local host?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM