Ядро asp.net 3.1. Задержка посадки запроса на сервер до момента его достижения - PullRequest
0 голосов
/ 23 декабря 2019

У меня есть приложение asp.net core 3.1, которое я изучаю на предмет задержек. Я наблюдаю за задержкой после поступления запроса на сервер до действия моего действия. Код моего приложения можно узнать по адресу https://github.com/aspnet/AspNetCore/issues/17985. Пожалуйста, дайте мне знать, что я должен сделать, чтобы избежать этой задержки. Мой текущий код запуска -

using log4net;
using log4net.Appender;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.HttpOverrides;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;

namespace MyApp
{
    public class Startup
    {



        private static readonly ILog Logger = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
        private const string MyAllowSpecificOrigins = "_myAllowSpecificOrigins";


        public Startup(IConfiguration configuration)
        {
            Configuration = configuration;
        }

        public 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.AddControllers(options => options.RespectBrowserAcceptHeader = true).AddXmlSerializerFormatters().AddXmlDataContractSerializerFormatters();//for twilio            
            CorsRelatedPolicyAddition(services);
            services.Configure<ForwardedHeadersOptions>(options =>
            {
                options.ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto;
            });
        }

        private void CorsRelatedPolicyAddition(IServiceCollection services)
        {
            List<string> lstofCors = new List<string>();//from some configruation
            if (lstofCors != null && lstofCors.Count > 0 && lstofCors.Any(h => !string.IsNullOrWhiteSpace(h)))
            {
                services.AddCors(options =>
                {
                    options.AddPolicy(MyAllowSpecificOrigins, builder => { builder.WithOrigins(lstofCors.ToArray()).AllowAnyMethod().AllowAnyHeader(); });
                });

            }
        }

        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env, IHostApplicationLifetime applicationLifetime)
        {

            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            app.UseMiddleware<RequestLoggingMiddleware>();
            app.UseHttpsRedirection();
            app.UseRouting();
            app.UseCors(MyAllowSpecificOrigins);

            app.UseForwardedHeaders();
            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllerRoute("default", "{controller=Home}/{action=Index}/{id?}");
            });

            //app.UseMvc(); //this is changed in 3.0
            applicationLifetime.ApplicationStarted.Register(StartedApplication);
            applicationLifetime.ApplicationStopping.Register(OnShutdown);
        }


        private void OnShutdown()
        {
            try
            {
                Logger.Debug("Flushing out messages");

                var rep = LogManager.GetRepository(Assembly.GetEntryAssembly());
                foreach (var appender in rep.GetAppenders())
                {
                    var buffered = appender as BufferingAppenderSkeleton;
                    if (buffered != null)
                    {
                        buffered.Flush();
                    }
                }

            }
            catch (Exception ex)
            {
                Logger.Fatal(ex, ex);
            }
        }

        private void StartedApplication()
        {
            Logger.Debug("Application Started");
        }
    }
}
...