All posts

Fix NotFoundError in C# When Deploying

Resolve 404 and FileNotFoundException in C# .NET deployments caused by missing files, incorrect publish profiles, and IIS configuration.

C# Deployment NotFoundError

Deploying .NET apps and getting FileNotFoundException or 404 errors usually means the publish output is incomplete or the server isn't configured to route requests to the .NET process.

Publish Profile Issues

# Ensure all files are included
dotnet publish -c Release -o ./publish --self-contained false

Check that appsettings.json and static files are in the output:

<!-- .csproj — include config files -->
<ItemGroup>
  <Content Include="appsettings*.json">
    <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
  </Content>
</ItemGroup>

IIS Configuration

For IIS hosting, install the ASP.NET Core Hosting Bundle and configure:

<!-- web.config -->
<configuration>
  <system.webServer>
    <handlers>
      <add name="aspNetCore" path="*" verb="*"
           modules="AspNetCoreModuleV2" resourceType="Unspecified" />
    </handlers>
    <aspNetCore processPath="dotnet" arguments=".\MyApp.dll"
                stdoutLogEnabled="true" stdoutLogFile=".\logs\stdout" />
  </system.webServer>
</configuration>

Static Files Middleware Order

var app = builder.Build();

// Order matters!
app.UseStaticFiles();  // Must be before routing
app.UseRouting();
app.UseAuthorization();
app.MapControllers();
app.MapFallbackToFile("index.html"); // SPA fallback

Docker Deployment

FROM mcr.microsoft.com/dotnet/aspnet:8.0
WORKDIR /app
COPY --from=builder /app/publish .
ENTRYPOINT ["dotnet", "MyApp.dll"]

Bugsly captures FileNotFoundException and 404 responses in .NET with the full request path, making it clear which file or route is missing.

Try Bugsly Free

AI-powered error tracking that explains your bugs. Set up in 2 minutes, free forever for small projects.

Get Started Free