1

Проблема была в том, что любые попытки подключиться к хабу заканчивались ответом сервера 404 (not found). Код в Startup был следующий:

public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
    if (env.IsDevelopment())
        app.UseDeveloperExceptionPage();

    app.UseRouting();
    app.UseDefaultFiles();
    app.UseStaticFiles();

    AppContext.SetSwitch("Npgsql.EnableLegacyTimestampBehavior", true);
    AppContext.SetSwitch("Npgsql.DisableDateTimeInfinityConversions", true);

    app.UseOwin(x => x.UseNancy());

    app.UseEndpoints(endPoint =>
    {
        endPoint.MapHub<OrderHub>("/ordersNotification");
    });
}

public void ConfigureServices(IServiceCollection services)
{
    services.AddMvc();

    services.AddDbContext<DataContext>(options =>
    {
        options
            .UseNpgsql(_configuration.GetConnectionString("DefaultConnection"),
                assembly =>
                    assembly.MigrationsAssembly("ASPHost"));
    });

    ConfigureRepository.ConfigureService(services);
    ConfigureServiceBase.ConfigureService(services);
    ConfigureMapper.ConfigureService(services);
    ConfigureController.ConfigureService(services);
    ConfigureCache.ConfigureService(services);

    services.AddSignalR();
}

1 ответ 1

2

Решение, на которое я потратил почти 2 суток, оказалось крайне простым - поменять местами UseOwin... и UseEndpoints.... Итого, метод Configure должен выглядеть следующим образом:

public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
    if (env.IsDevelopment())
        app.UseDeveloperExceptionPage();

    app.UseRouting();
    app.UseDefaultFiles();
    app.UseStaticFiles();

    AppContext.SetSwitch("Npgsql.EnableLegacyTimestampBehavior", true);
    AppContext.SetSwitch("Npgsql.DisableDateTimeInfinityConversions", true);

    app.UseEndpoints(endPoint =>
    {
        endPoint.MapHub<OrderHub>("/ordersNotification");
    });

    app.UseOwin(x => x.UseNancy());
}

Надеюсь, этот ответ сможет спасти чью-нибудь ж*пу от сгорания

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.