Raspberry Pi request to Azure .NET Core 2.2 API works, but on .NET 6 it doesn't work

Viewed 37

I have very strange problem. I'm migrating from ASP.NET Core 2.2 to ASP.NET Core 6 on Azure. I have several modified Raspberry Pi that make request every 10 seconds to .NET Core portal after some operations response back.

On localhost, everything works perfectly fine, test it with Postman, but when I publish the project to Azure, the requests stop working, but with Postman request they still working on live.

I use Nlog, and there are no errors.

Is there can be some firewall that added to .NET Core 6, because on .NET Core 2.2 everything is working.

My API code:

[Route("api/[controller]")]
[...ApiController]
public class ...ApiController : ControllerBase
{
   private readonly ILogger<...ApiController> _logger;

   public ...ApiController(ILogger<...ApiController> logger)
   {
       _logger = logger;
   }

   [HttpPost]
   public string GetWithBody([FromBody] S...Get s...Get)
   {     
   }
}

My Program.cs:

    var builder = WebApplication.CreateBuilder(args);builder.Logging.ClearProviders();
    builder.Host.UseNLog();

    var connectionString = builder.Configuration.GetConnectionString("DefaultConnection");
    builder.Services.AddDbContext<AccessKeyDbContext>(options =>
        options.UseSqlServer(connectionString));
    builder.Services.AddDatabaseDeveloperPageExceptionFilter();

    builder.Services.AddIdentity<ApplicationUser, ApplicationRole>(identityOptions =>
        {
            identityOptions.Password.RequireDigit = false...
            identityOptions.User.AllowedUserNameCharacters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-._@+";
        }).AddEntityFrameworkStores<AccessKeyDbContext>().AddDefaultTokenProviders();
    builder.Services.AddControllersWithViews().AddViewLocalization(); ;
    builder.Services.AddHealthChecks();
    builder.Services.AddRazorPages();
    builder.Services.AddControllersWithViews().AddRazorRuntimeCompilation();
    builder.Services.Configure<FormOptions>(options => options.ValueCountLimit = 5000);
    builder.Services.ConfigureApplicationCookie(options =>
    {
        options.AccessDeniedPath = "/Account/AccessDenied";

        options.LoginPath = "/Identity/Account/Login";
    });

    var keysFolder = Path.Combine(builder.Environment.ContentRootPath, "Keys");

    builder.Services.AddDataProtection()
    .SetApplicationName("AccessKey")
    .SetDefaultKeyLifetime(TimeSpan.FromDays(90))
    .PersistKeysToFileSystem(new DirectoryInfo(keysFolder));

    builder.Services.Configure<JsonOptions>(options =>
    {
        options.SerializerOptions.PropertyNameCaseInsensitive = true;
    });

    builder.Services.AddLocalization(options => options.ResourcesPath = "Resources");
    builder.Services.AddSingleton<ILocService, LocService>();

    builder.Services.Configure<RequestLocalizationOptions>(
    opts =>
    {
        var supportedCultures = new List<CultureInfo>
        {
                    new CultureInfo("en-US")
        };
        opts.DefaultRequestCulture = new RequestCulture(culture: "en-US", uiCulture: "en-US");
        opts.SupportedCultures = supportedCultures;
        opts.SupportedUICultures = supportedCultures;

        opts.RequestCultureProviders.Insert(0, new QueryStringRequestCultureProvider());
    });
    builder.Services.AddMServices();

    builder.Services.ConfigureApplicationCookie(options =>
    {
        options.LoginPath = $"/Identity/Account/Login";
        options.LogoutPath = $"/Identity/Account/Logout";
        options.AccessDeniedPath = $"/Identity/Account/AccessDenied";
        options.Cookie.IsEssential = true;
        options.SlidingExpiration = true;
        options.ExpireTimeSpan = TimeSpan.FromSeconds(900);
    });

    builder.Services.Configure<GzipCompressionProviderOptions>
        (options => options.Level = CompressionLevel.Fastest);
    builder.Services.AddResponseCompression(options =>
    {
        options.Providers.Add<GzipCompressionProvider>();
        options.EnableForHttps = true;
    });

    var app = builder.Build();

    if (app.Environment.IsDevelopment())
    {
        app.UseMigrationsEndPoint();
    }
    else
    {
        app.UseExceptionHandler("/Home/Error");
        app.UseHsts();
    }

    app.UseRequestLocalization();
    app.UseHttpsRedirection();
    app.UseStaticFiles();

    app.UseRouting();

    app.UseAuthentication();
    app.UseAuthorization();

    app.MapControllerRoute(
        name: "MyAdmin",
        pattern: "{area:exists}/{controller=Home}/{action=Index}/{id?}");
    app.MapControllerRoute(
        name: "default",
        pattern: "{controller=Home}/{action=Index}/{id?}");

    app.MapRazorPages();
    app.Run();

I am grateful for any straw that will help me find the problem.

Thank you for your time!

P.S. Big thank to marc_s for the editing and made my question look better, I will take notes for next questions!

0 Answers
Related