First, this app was originally created with .NET 6 and was later migrated to .NET 8. The application operates as a Blazor Server app. We are trying to deploy it on Azure now as an App Service (Windows).
The application initially runs and connects to the SQL Server database successfully, but after the Startup completes, I am getting an error: An attempt was made to access a socket in a way forbidden by its access permissions.
To ensure that there wasn't a basic problem in the cloud setup, I deployed the barebones Blazor Web App with examples. I also added the entity framework package and a small DbContext class.
The application that is failing is mature and uses Negotiate authentication. I haven't tried this is yet though as I believe this problem is unrelated. For now, I would just like to see the application successfully start.
We do have kestrel information in the config file. I believe it normally defaults to 5000 and 5001:
"Kestrel": {"EndPoints": {"Http:Url": "http://*:80","HttpsDefaultCert:Url": "https://*:443" },"Certificates": {"Default": {"Path": "certificate.pfx","Password": "[some-password]" } } }}In the past, we've installed this on bare metal servers as a windows service running Kestrel and never through IIS. I know that the App Service (Windows) options rely's on IIS and I feel that something is off here. I've tried removing and changing the ports. This gives me an error about ports already in use.
Another difference between the barebones application is that it is configured using WebApplication.CreateBuilder() whereas, our mature application uses an IWebHostBuilder through IHostBuilder with a Startup class. I'm not sure if the result is actually different.
Program.cs:
public class Program{ public static void Main(string[] args) { CreateHostBuilder(args).Build().Run(); } public static IHostBuilder CreateHostBuilder(string[] args) => Host.CreateDefaultBuilder(args) .ConfigureWebHostDefaults(webBuilder => { webBuilder.ConfigureAppConfiguration((hostingContext, config) => { var hostingEnv = hostingContext.HostingEnvironment; if (hostingEnv.IsProduction()) Directory.SetCurrentDirectory(AppDomain.CurrentDomain.BaseDirectory); config.SetBasePath(Directory.GetCurrentDirectory()) .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true) .AddJsonFile($"appsettings.{hostingEnv.EnvironmentName}.json", optional: true, reloadOnChange: true) .AddEnvironmentVariables(); }); webBuilder.UseStartup<Startup>(); });}Startup.cs:
public class Startup{ private readonly IWebHostEnvironment env; public Startup(IConfiguration configuration, IWebHostEnvironment env) { Configuration = configuration; this.env = env; } public IConfiguration Configuration { get; } // This method gets called by the runtime. Use this method to add services to the container. // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940 public void ConfigureServices(IServiceCollection services) { services.AddAuthentication(NegotiateDefaults.AuthenticationScheme).AddNegotiate(); services.AddRouting(); services.AddAuthorization(options => { options.FallbackPolicy = options.DefaultPolicy; options.AddPolicy("DashboardViewer", p => { p.RequireRole("ManageProjects", "ViewProject", "ModifyProject", "ManageSystems", "ViewSystem", "ModifySystem"); }); }); services.AddRazorPages(); services.AddServerSideBlazor(); string connectionString = Configuration.GetConnectionString("DefaultConnection"); services.AddDbContextFactory<CgContext>(options => { options.UseSqlServer(connectionString) .UseLazyLoadingProxies(); }); services.AddHttpContextAccessor(); services.AddScoped<IClaimsTransformation, ClaimsTransformer>(); services.AddDatabaseDeveloperPageExceptionFilter(); } // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, CgContext context, ILogger<Startup> logger, PluginDataLoader pluginLoader) { app.UseExceptionHandler("/Error"); app.UseHsts(); app.UseHttpsRedirection(); app.UseStaticFiles(); app.UseRouting(); app.UseAuthentication(); app.UseAuthorization(); app.UseEndpoints(endpoints => { endpoints.MapControllers(); endpoints.MapBlazorHub(); endpoints.MapFallbackToPage("/_Host"); }); try { context.Database.Migrate(); } catch (Exception e) { logger.LogError(e, "Application DB startup failed."); throw; } }}Please let me know if there's anything else I can show. I so know that startup completes as I have a completely initialized database.
Thanks in advance.