ASP.Net Core 2.2无法在Azure webApp上呈现完整的HTML

问题描述 投票:0回答:1

我有一个正在运行的ASP.Net Core 2.2 webapp,大多数情况下,这个运行正常,但是有时它会停止在HTML文档中的任意位置呈现HTML。这仅在天蓝色的环境中发生,在本地运行正常!

我几天来一直在看这个东西,但是我的想法已经用光了。

某些上下文:

  • 它正在进程模式下运行(进程也失败了。)>
  • 负载均衡,我检查了所有实例,它们看起来很正常。
  • 它在Controller中进行了一些异步处理,但是等待所有调用。
  • 我已经检查了错误日志,诊断信息以及所有内容,但我只是找不到问题。
  • Program.cs

 public static IWebHost BuildWebHost(string[] args) =>
            WebHost.CreateDefaultBuilder(args)
                .ConfigureKestrel(options => {
                        options.AddServerHeader = false;
                        options.Limits.MaxRequestBodySize = 52428800;

                }
                )
                .UseIISIntegration()
                .UseStartup<Startup>()
                .UseUrls("http://localhost:44309", "https://0.0.0.0:44310")
                .Build();
    }

Startup.cs

    [SuppressMessage("ReSharper", "UnusedMember.Global")]
    [SuppressMessage("ReSharper", "ClassNeverInstantiated.Global")]
    public class Startup
    {
        public Startup(IConfiguration configuration)
        {

            Configuration = configuration;
        }

        private IConfiguration Configuration { get; }

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


            services.RegisterProviders(Configuration);

            services.AddMvc(opts =>
            {
                opts.Filters.Add(typeof(AdalTokenAcquisitionExceptionFilter));
            }).AddRazorPagesOptions(options =>
            {
                options.Conventions.AllowAnonymousToPage("/error");
                options.Conventions.AllowAnonymousToFolder("/app");
            }).SetCompatibilityVersion(CompatibilityVersion.Version_2_2)
               .AddJsonOptions(options =>
               {
                   options.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;
                   options.SerializerSettings.NullValueHandling = NullValueHandling.Ignore;
               }
            );

            services.ConfigureExternalCookie(options =>
            {
                options.Cookie.SameSite = SameSiteMode.None;
            }); services.ConfigureApplicationCookie(options =>
            {
                options.Cookie.SameSite = SameSiteMode.None;
            });

            services.AddAuthentication(sharedOptions =>
                {
                    sharedOptions.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme;
                    sharedOptions.DefaultChallengeScheme = OpenIdConnectDefaults.AuthenticationScheme;
                    sharedOptions.DefaultSignInScheme = CookieAuthenticationDefaults.AuthenticationScheme;
                })
                .AddCookie(c =>
                {
                    c.SessionStore = new RedisCacheTicketStore(services.BuildServiceProvider().GetService<IDistributedCache>());
                    c.Cookie.Name = "snps";
                    c.Cookie.SameSite = SameSiteMode.None; // if changing Safari keeps redirecting back and forth when signin at microsoftonline.com ...
                })
                .AddAzureAd(options =>
                {
                    Configuration.Bind("AzureAd", options);
                }, Configuration);

            services.AddCors();



            services.AddNodeServices(options =>
            {
                options.LaunchWithDebugging = true;
                options.DebuggingPort = 9229;
            });

            //Add distributed cache service backed by Redis cache
            services.AddDistributedRedisCache(o =>
            {
                o.Configuration = Configuration.GetConnectionString("RedisCache");
            });

            services.Configure<CookieTempDataProviderOptions>(options =>
            {
                options.Cookie.Name = "tmp";
            });
        }

        // 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())
            {
                try
                {
                    //app.UseExceptionHandler("/Error");
                    app.UseDeveloperExceptionPage();
                    app.UseWebpackDevMiddleware(new WebpackDevMiddlewareOptions
                    {
                        ConfigFile = "./webpack.development.config.js",
                        HotModuleReplacement = true,
                        HotModuleReplacementServerPort = 8082

                    });
                }
                catch (Exception ex)
                {
                    Debug.WriteLine(ex.Message);
                    Debug.WriteLine(ex.StackTrace);
                }
            }
            else
            {
                app.UseExceptionHandler("/Error");

            }

            app.UseCookiePolicy(new CookiePolicyOptions
            {
                MinimumSameSitePolicy = SameSiteMode.None // else safari ends up in an infinite loop when signing in
            });

            var provider = new FileExtensionContentTypeProvider();
            provider.Mappings[".ttf"] = "application/octet-stream";
            app.UseDefaultFiles();
            app.UseStaticFiles(new StaticFileOptions
            {
                ContentTypeProvider = provider
            });
            app.UseAuthentication();
            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "default",
                    template: "{controller=Home}/{action=Index}/{id?}");


                routes.MapRoute("signin", "signin", defaults: new { controller = nameof(HomeController), action = "SignIn" });

                routes.MapSpaFallbackRoute(
                    name: "spa-fallback",
                    defaults: new { controller = "Home", action = "Index" });
            });

        }
    }

我有一个正在运行的ASP.Net Core 2.2 webapp,大多数情况下,这个运行正常,但是有时它会停止在HTML文档中的任意位置呈现HTML。仅此...

asp.net-core azure-web-sites asp.net-core-2.2
1个回答
0
投票

恭喜您找到了解决方法:

© www.soinside.com 2019 - 2024. All rights reserved.