.net核心服务中的超时

时间:2018-11-22 16:48:48

标签: .net-core timeout asp.net-core-mvc asp.net-core-webapi

我有一个.NET Core服务,我将其作为应用程序服务托管在Azure中。 默认情况下,它在2分钟后超时,但是随后我将requestTimeout =“ 00:30:00”添加到了web.config的aspNetCore元素中。

但是,这会将超时时间仅延长到大约4分钟。

我正在寻找该价值的来源以及如何增加它。

下面是BuildWebHost方法和启动方法:配置和配置我使用的服务。

public static IWebHost BuildWebHost(string[] args) =>
    WebHost.CreateDefaultBuilder(args)
        .ConfigureAppConfiguration((context, config) =>
        {
            IHostingEnvironment env = context.HostingEnvironment;
            config.SetBasePath(Directory.GetCurrentDirectory())
                .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
                .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true, reloadOnChange: true)
                .AddEnvironmentVariables();

            config.AddAzureKeyVault(
                Environment.GetEnvironmentVariable("Vault"),
                Environment.GetEnvironmentVariable("VaultClientId"),
                Environment.GetEnvironmentVariable("VaultClientSecret")
            );

            var builtConfig = config.Build();
        })
        .ConfigureServices(services =>
        {
            // my services here
        })
        .UseStartup<Startup>()
        .Build();
}

public void ConfigureServices(IServiceCollection services)
{
    services.AddCors();

    // my interfaces here

    services.AddAuthentication(sharedOptions =>
    {
        sharedOptions.DefaultScheme = JwtBearerDefaults.AuthenticationScheme;
    })
    .AddJwtBearer("Jwt", options =>
    {
        options.TokenValidationParameters = new TokenValidationParameters
        {
            ValidateIssuer = true,
            ValidateAudience = true,
            ValidateLifetime = true,
            ValidateIssuerSigningKey = true,
            ValidIssuer = Configuration["Jwt:Issuer"],
            ValidAudience = Configuration["Jwt:Issuer"],
            IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(Environment.GetEnvironmentVariable("JWT_KEY")))
        };
    })
    .AddScheme<AuthenticationSchemeOptions, ApiKeyHandler>("ApiKey", null);

    services.AddLogging(builder =>
    {
        builder.AddConfiguration(Configuration.GetSection("Logging"))
        .AddConsole()
        .AddDebug();
    });

    services.AddResponseCaching();

    services.AddSwaggerGen(c =>
    {
        c.SwaggerDoc("v1", new Info { Title = "MyApp", Version = "v1" });
    });

    services.AddMvc();
}

public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
    app.UseCors(builder =>
    {
        builder.WithOrigins("*")
        .AllowAnyHeader()
        .AllowAnyMethod()
        .AllowCredentials();
    });

    app.UseDeveloperExceptionPage();
    app.UseSwagger();
    app.UseSwaggerUI(c =>
    {
        c.RoutePrefix = string.Empty;
        c.SwaggerEndpoint("/swagger/v1/swagger.json", "MyApp");
    });

    app.UseResponseCaching();
    app.UseAuthentication();
    app.UseMvc();
}

这也是我的web.config供参考:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <location path="." inheritInChildApplications="false">
    <system.webServer>
      <handlers>
        <add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified" />
      </handlers>
      <aspNetCore requestTimeout="00:30:00" processPath="dotnet" arguments=".\MyApp.dll" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" />
    </system.webServer>
  </location>
</configuration>

任何帮助将不胜感激。

0 个答案:

没有答案