首页 > 解决方案 > Spa with Net5.0避免了QueryString的丢失

问题描述

因为我不是本地人,所以我的英语。首先我使用 Angular front/Net 5.0 back。我的问题是,每次我去我的 Spa 应用程序(从另一个处理登录的应用程序)时,我都会丢失查询字符串并重定向到 /,我如何配置应用程序以不丢失查询字符串?这是我的配置服务。

  public void ConfigureServices(IServiceCollection services)
    {
        string mySqlConnectionStr = Configuration.GetConnectionString("DefaultConnection");
        services.AddControllers();
        services.AddDbContextPool<recursoContext>(options => options.UseMySQL(mySqlConnectionStr));
        services.AddLogging();
        
        services.AddSwaggerGen(c =>
        {
            c.SwaggerDoc("v1", new OpenApiInfo { Title = "WebContainerUI", Version = "v1" });
        });
        services.AddSpaStaticFiles(configuration =>
        {
            configuration.RootPath = "/";
            
        });
    }

这是我的配置

public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
    {
        if (env.IsDevelopment())
        {
            app.UseDeveloperExceptionPage();
            app.UseSwagger();
            app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "WebContainerUI v1"));
        }

        app.UseHttpsRedirection();
        app.UseDefaultFiles();
        app.UseStaticFiles();
        app.UseRouting();
        app.UseMiddleware<Jwt.JwtMiddleware>();
        app.UseAuthorization();
        app.UseEndpoints(endpoints =>
        {
            endpoints.MapControllers();
            endpoints.MapFallbackToFile("/index.html");
        });

        app.UseSpa(spa =>
        {
            // To learn more about options for serving an Angular SPA from ASP.NET Core,
       

            if (env.IsDevelopment())
            {
                // spa.UseAngularCliServer(npmScript: "start");
            }
        });
       
    }

此外,应用程序的目标是将 JwT 处理为一种没有会话的身份验证方法(那里没有 cookie)。由于我正在学习不知道将其结合起来的最佳方法,因此想听听一些建议。谢谢你的帮助。

标签: angularsingle-page-applicationasp.net-core-5.0fallbackquerystringparameter

解决方案


只是如果有人有同样的问题,它与.Net Core的Spa重定向/回退无关,问题出在角度(客户端)如何做路由,所以令牌被前面接收,但不知何故被删除了重定向(客户端)。


推荐阅读