Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/61.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
.net core 从.net core 2.2迁移到3.1-api 404错误_.net Core_.net Core 2.2_.net Core 3.1 - Fatal编程技术网

.net core 从.net core 2.2迁移到3.1-api 404错误

.net core 从.net core 2.2迁移到3.1-api 404错误,.net-core,.net-core-2.2,.net-core-3.1,.net Core,.net Core 2.2,.net Core 3.1,我开发了一个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 a

我开发了一个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" }
            //     );
            // });
        }
    }
}

名称空间HostSystems.API
{
公营创业
{
//此方法由运行时调用。请使用此方法将服务添加到容器中。
public void配置服务(IServiceCollection服务)
{
services.AddMvc(选项=>
{
var policy=new AuthorizationPolicyBuilder()
.RequireAuthenticatedUser()文件
.Build();
options.Filters.Add(新的授权过滤器(策略));
}).SetCompatibilityVersion(CompatibilityVersion.Latest)
.AddNewtonsoftJson(opt=>
{
opt.SerializerSettings.ReferenceLoopHandling=
Newtonsoft.Json.ReferenceLoopHandling.Ignore;
opt.SerializerSettings.TypeNameHandling=TypeNameHandling.Auto;
opt.SerializerSettings.SerializationBinder=
新CustomJsonSerializationBinder();
opt.SerializerSettings.MetadataPropertyHandling=MetadataPropertyHandling.ReadAhead;
})
;
services.AddCors();
services.Configure(Configuration.GetSection(“CloudinarySettings”);
services.addScope();
services.addScope();
services.AddTransient();
services.AddTransient();
services.AddTransient();
services.AddTransient();
services.AddTransient();
services.AddTransient();
services.AddTransient();
services.AddTransient();
services.addScope();
services.AddSignalR();
}
//此方法由运行时调用。请使用此方法配置HTTP请求管道。
公共无效配置(IApplicationBuilder应用程序,
IHostingEnvironment(环境)
{
if(env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
其他的
{
app.UseExceptionHandler(生成器=>
{
运行(异步上下文=>
{
context.Response.StatusCode=(int)HttpStatusCode.InternalServerError;
var error=context.Features.Get();
if(错误!=null)
{
context.Response.AddApplicationError(error.error.Message);
wait context.Response.WriteAsync(error.error.Message);
}
});
});
}
app.UseCors(x=>
x、 来源(“http://localhost:5000", "http://localhost:4200")
.AllowAnyHeader().AllowAnyMethod().AllowCredentials());
//app.UseForwardedHeaders(新ForwardedHeaders选项
// {
//ForwardedHeaders=ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto
// });
app.UseAuthentication();
app.UseDefaultFiles();
app.UseStaticFiles();
//此方法已过时,将在将来的版本中删除
app.usesigner(路由=>
{
routes.MapHub(“/loopy”);
});
//这在.NETCoreV3.1->中被贬低了,因为现在没有退路,您必须找到替代解决方案
//app.UseMvc(路由=>
// {
//routes.MapSpaFallbackRoute(
//名称:“水疗后援”,
//默认值:新建{controller=“Fallback”,action=“Index”}
//     );
// });
}
}
}

因为我不知道从哪里开始,请告诉我还有什么可以帮助我。

你好,小猫,谢谢你的输入。我不太确定startup.cs中发生的事情,但我通过添加app.UseEndpoints(endpoints=>{endpoints.MapControllers();})解决了这个问题;