Миграция с. net core 2.2 на 3.1 - ошибка API 404 - PullRequest
0 голосов
/ 20 января 2020

Я разрабатываю SPA с. net ядром на стороне сервера (и Angular для клиентов). После перехода с. net core 2.2 на 3.1 API-интерфейс систематически отвечает с ошибкой 404. Я понятия не имею, где попасть в проблему.

Вот содержимое файла Startup.cs. Большое спасибо за любую подсказку!


namespace HostSystems.API
{
    public class Startup
    {



        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {

            services.AddMvc(options =>
            {
                var policy = new AuthorizationPolicyBuilder()
                    .RequireAuthenticatedUser()
                    .Build();
                options.Filters.Add(new AuthorizeFilter(policy));
            }).SetCompatibilityVersion(CompatibilityVersion.Latest)
            .AddNewtonsoftJson(opt =>
            {
                opt.SerializerSettings.ReferenceLoopHandling =
                    Newtonsoft.Json.ReferenceLoopHandling.Ignore;
                opt.SerializerSettings.TypeNameHandling = TypeNameHandling.Auto;
                opt.SerializerSettings.SerializationBinder =
                new CustomJsonSerializationBinder();
                opt.SerializerSettings.MetadataPropertyHandling = MetadataPropertyHandling.ReadAhead;
            })
            ;
            services.AddCors();
            services.Configure<CloudinarySettings>(Configuration.GetSection("CloudinarySettings"));
            services.AddScoped<IHsRepository, HsRepository>();
            services.AddScoped<PermissionService>();
            services.AddTransient<Seed>();
            services.AddTransient<GeneralMap>();
            services.AddTransient<EventMap>();
            services.AddTransient<LegalEntityMap>();
            services.AddTransient<UserMap>();
            services.AddTransient<ProviderMap>();
            services.AddTransient<LicenseeMap>();
            services.AddTransient<SItemMap>();
            services.AddScoped<LogUserActivity>();
            services.AddSignalR();
        }

        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app,
            IHostingEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler(builder =>
                {
                    builder.Run(async context =>
                    {
                        context.Response.StatusCode = (int)HttpStatusCode.InternalServerError;

                        var error = context.Features.Get<IExceptionHandlerFeature>();
                        if (error != null)
                        {
                            context.Response.AddApplicationError(error.Error.Message);
                            await context.Response.WriteAsync(error.Error.Message);
                        }
                    });
                });
            }

            app.UseCors(x =>
                x.WithOrigins("http://localhost:5000", "http://localhost:4200")
                .AllowAnyHeader().AllowAnyMethod().AllowCredentials());

            // app.UseForwardedHeaders(new ForwardedHeadersOptions
            // {
            //     ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto
            // });

            app.UseAuthentication();
            app.UseDefaultFiles();
            app.UseStaticFiles();

            // This method is obsolete and will be removed in a future version
            app.UseSignalR(routes =>
                 {
                     routes.MapHub<TestHub>("/loopy");
                 });

            // This got depreciated with .net core v 3.1 -> for now there is no fallback, you have to find the alternative solution
            // app.UseMvc(routes =>
            // {
            //     routes.MapSpaFallbackRoute(
            //         name: "spa-fallback",
            //         defaults: new { controller = "Fallback", action = "Index" }
            //     );
            // });
        }
    }
}

Поскольку я не уверен, с чего начать, пожалуйста, дайте мне знать, что еще может быть полезным.

...