我正在.net核心应用程序内启动Vue SPA。静态MVC页面可以正确投放,但是当我导航到SPA路由时,出现此错误:
System.InvalidOperationException:响应内容长度不匹配:写入的字节过多(1372中的2598)。 在Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpProtocol.VerifyAndUpdateWrite(Int32 count) 在Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpProtocol.WriteAsync(ReadOnlyMemory`1 data,CancellationToken cancellingToken)
我尝试重新安装所有的node_modules并使用UseVueCli选项,但是都没有起作用。在启动.net应用之前,Vue应用已运行。
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();
}
}
当我导航到应该使用SPA的路线时,返回上面的错误。
答案 0 :(得分:0)
找到了解决方案。 stackify中间件已注册,这就是问题的原因。发表评论即可解决问题。