I am having an issue with my ASP.NET Core 8 Web API after deployment to a production site in IIS. In this case I have structured so that it is an application under an existing site (e.g. admin.example.com -> api). When navigating / posting to the endpoint I receive a http 404 error. When I dotnet the .dll file, I get this error:
An attempt was made to access a socket in a way forbidden by its access permissions (line 95)
My program.cs
(app.run
is @ line 95 in full code):
using Newtonsoft.Json.Linq;
using Models;
using System.Net;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Data.SqlClient;
using Microsoft.Extensions.Configuration;
var builder = WebApplication.CreateBuilder(args);
builder.WebHost.ConfigureKestrel((context, options) =>
{
options.Configure(context.Configuration.GetSection("Kestrel"));
});
builder.Services.AddControllers()
.AddNewtonsoftJson();
builder.Services.AddControllers();
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
var app = builder.Build();
// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI();
}
app.UseHttpsRedirection();
app.UseRouting();
app.UseAuthorization();
app.MapPost($"api/receivejson", async (HttpContext context) =>
{
// Do shit (no 404s)
});
app.MapControllers();
app.Run();
And my appsettings.json
file:
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"Kestrel": {
"Endpoints": {
"HttpsInlineCertFile": {
"Url": "https://admin.example.com",
"Certificate": {
"Path": "C:\Path\Here",
"Password": ""
}
}
}
},
"AllowedHosts": "*"
}
Web.config
:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<location path="." inheritInChildApplications="false">
<system.webServer>
<handlers>
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2"
resourceType="Unspecified" />
</handlers>
<aspNetCore processPath="dotnet" arguments=".MyApp.dll"
stdoutLogEnabled="false" stdoutLogFile=".logsstdout" hostingModel="inprocess" />
</system.webServer>
</location>
</configuration>
<!--ProjectGuid: GuidHere -->
Any help would be much appreciated – I’ve looked far and wide and have had no luck thus far.