I have an ASP.NET WEBAPI service running in Azure using Azure Active Directory and Azure SQL Server. I have gone into Azure App Services settings and turned on Always On, but I am sure the WEBAPI is unloading.
For testing I have a set of calls that usually take 4-5 seconds. Sometimes the calls take over 30 seconds.
Other than this occasional slow response, there are no issues.
The WEBAPI service has no viewable pages. API controllers only.
Probably not relevant, but I also use EF for data access. I also use CORS.
Here are my Azure App Settings:
[
{
"name": "ASPNETCORE_ENVIRONMENT",
"value": "Development",
"slotSetting": true
},
{
"name": "BasePath",
"value": "*****************************",
"slotSetting": true
},
{
"name": "WEBSITE_HTTPLOGGING_RETENTION_DAYS",
"value": "7",
"slotSetting": false
},
{
"name": "WEBSITE_RUN_FROM_PACKAGE",
"value": "1",
"slotSetting": false
}
]
Here is the Azure General Settings:
Here is most of my StartUp.cs file:
public void ConfigureServices(IServiceCollection services)
{
services.AddDbContext<DatabaseContext>(options =>
options.UseSqlServer(
Configuration.GetConnectionString("DefaultConnection"), o =>
{
o.EnableRetryOnFailure();
})
.ConfigureWarnings(warnings => warnings.Ignore(Microsoft.EntityFrameworkCore.Diagnostics.CoreEventId.ContextInitialized))
.EnableSensitiveDataLogging(true));
services
.AddAuthentication("Azure")
.AddPolicyScheme("Azure", "Authorize AzureAd or AzureAdBearer", options =>
{
options.ForwardDefaultSelector = context =>
{
var authHeader = context.Request.Headers["Authorization"].FirstOrDefault();
if (authHeader?.StartsWith("Bearer") == true)
{
return JwtBearerDefaults.AuthenticationScheme;
}
return AzureADDefaults.AuthenticationScheme;
};
})
.AddJwtBearer(opt =>
{
opt.Audience = Configuration["AAD:ResourceId"];
opt.Authority = $"{Configuration["AAD:Instance"]}{Configuration["AAD:TenantId"]}";
})
.AddAzureAD(options => Configuration.Bind("AzureAd", options));
var origins = Configuration.GetSection("AppSettings:AllowedOrigins").Value.Split(",");
services.AddCors(o => o.AddPolicy(specificOrigins, builder =>
{
builder.WithOrigins(origins)
.AllowAnyMethod()
.AllowAnyHeader()
.AllowCredentials()
.SetIsOriginAllowed((host) => true);
}));
services.Configure<CookiePolicyOptions>(options =>
{
options.MinimumSameSitePolicy = SameSiteMode.Strict;
options.HttpOnly = Microsoft.AspNetCore.CookiePolicy.HttpOnlyPolicy.Always;
options.Secure = CookieSecurePolicy.Always;
});
services.AddResponseCaching();
services.AddControllers();
services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();
services.AddScoped<LogUserActivity>();
services.AddSession();
services.AddHttpContextAccessor();
services.AddAutoMapper();
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, ILoggerFactory loggerFactory)
{
loggerFactory.AddSerilog();
if (_currentEnvironment.IsDevelopment() || _currentEnvironment.IsEnvironment("LOCAL"))
{
app.UseDeveloperExceptionPage();
}
else
{
app.UseExceptionHandler("/Home/Error");
app.UseHsts();
}
app.UseCors(specificOrigins);
app.UseHttpsRedirection();
app.UseSession();
app.UseStaticFiles();
app.UseRouting();
app.UseResponseCaching();
app.UseCookiePolicy();
app.UseAuthentication();
app.UseAuthorization();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
endpoints.MapDefaultControllerRoute();
});
}