简体   繁体   中英

Response Content-length mismatch when running Vue SPA in .Net Core App

I am starting a Vue SPA inside of a .net core app. The static MVC page is served correctly, but when I navigate to the SPA route I get this error:

System.InvalidOperationException: Response Content-Length mismatch: too many bytes written (2598 of 1372). at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpProtocol.VerifyAndUpdateWrite(Int32 count) at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpProtocol.WriteAsync(ReadOnlyMemory`1 data, CancellationToken cancellationToken)

I have tried reinstalling all node_modules and using the UseVueCli options, but neither have worked. The Vue app is running before starting the .net app.

public class Startup
{
    public Startup(IHostingEnvironment env)
    {
        var builder = new ConfigurationBuilder()
            .SetBasePath(env.ContentRootPath)
            .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
            .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: false)
            .AddEnvironmentVariables();
        Configuration = builder.Build();
    }

    public IConfigurationRoot Configuration { get; set; }

    public void ConfigureServices(IServiceCollection services)
    {
        services.AddCors(options =>
        {
            options.AddPolicy(
                "*",
                builder =>
                {
                    builder
                        .WithOrigins("")
                        .WithMethods("GET")
                        .AllowAnyHeader()
                        .AllowCredentials();
                });
        });

        services.AddSingleton(Configuration);

        //Add all initial dependencies which can be used anywhere
        services.AddInitialDependencies();

        services.AddCaching();
        services.AddResponseCaching();

        services.AddFrameworks();
        services.AddSecurity(Configuration);
        services.AddDbContexts();
        services.AddSettingsProviders();
        services.AddLogicClasses();
        services.AddRealtimeClasses();

        services.AddAutoMapper((IMapperConfigurationExpression mapperConfiguration) =>
        {
            mapperConfiguration.CreateMissingTypeMaps = false;
        });

        services.AddSignalR();
    }

    public void Configure(IApplicationBuilder app, IHostingEnvironment env, IServiceProvider serviceProvider, IMapper autoMapper)
    {
        app.StartDbConfiguration(serviceProvider);

        app.UseHttpContextLogging();
        app.ConfigureErrorHandling(env);

        app.UseRequestLocalization();

        app.ConfigureHealthChecks();

        app.UseStaticFiles();
        app.UseSpaStaticFiles();

        JwtSecurityTokenHandler.DefaultInboundClaimTypeMap.Clear();

        app.UseAuthentication();
        app.UseClaimsLogging();

        app.UseResponseCaching();

        app.ConfigureRequestValidation();

        app.UseRewriter();

        app.ConfigureRealtime();

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

        app.UseMvc(routes =>
        {
          routes.MapRoute(
                name: "defaultRoute",
                template: "{controller=Home}/{action=Index}/{id?}");
        });

        app.UseSpa(spa =>
        {
            if (env.IsDevelopment())
            {
                spa.UseProxyToSpaDevelopmentServer("http://localhost:9051");
            }
        });

        // Configure Kendo UI
        app.UseKendo(env);

        autoMapper.ConfigurationProvider.AssertConfigurationIsValid();
    }
}

When I navigate to the route that the SPA should be served on, I am returned with the error above.

Found the solution. The stackify middleware was registered and that was the cause of the problem. Commenting it out resolved the issue.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM