.NET 7 Web Application sending an HTTP Error 403.14 - Forbidden The Web server is configured to not list the contents of this directory

81 views Asked by At

I know there's a lot of topics with the same error message, to be honest, I tried many of them, but none has worked so far, that's why I'm creating this post.

I'm trying to publish a .NET 7 web application, developed with Visual Studio 2022, on an IIS server. The configuration on my IIS server seems good, because I've tested it with a simple web application, the one we get after creating a new VS file, and it's working.

So I'm thinking about a problem with the configuration of the application itself.

Here is the Program.cs file:

    using Microsoft.EntityFrameworkCore;
    using NewJoinersWebApp.Data;
    using NewJoinersWebApp.Models;
    using Rotativa.AspNetCore;
    
    var builder = WebApplication.CreateBuilder(args);
    
    // Add services to the container.
    builder.Services.AddControllersWithViews();
    
    builder.Services.AddDbContext<AppDbContext>(options =>
    options.UseSqlServer(builder.Configuration.GetConnectionString("DefaultConnection")));
    
    //this is to configure the DbContext for LoginUser interface
    //builder.Services.AddDbContext<AppDbContextLoginUser>(options =>
    //options.UseSqlServer(builder.Configuration.GetConnectionString("DefaultConnection")));
    //builder.Services.AddIdentity<LoginUsers, Role>().AddEntityFrameworkStores<AppDbContextLoginUser>();
    
    
    var app = builder.Build();
    
    // Configure the HTTP request pipeline.
    if (!app.Environment.IsDevelopment())
    {
        app.UseExceptionHandler("/Home/Error");
        // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
        app.UseHsts();
    }
    
    app.UseHttpsRedirection();
    app.UseStaticFiles();
    
    app.UseRotativa();
    
    
    app.UseRouting();
    
    //add the control on the Http server
    //app.UseAuthentication();
    
    app.UseAuthorization();
    
    //app.MapFallbackToFile("/NotFound", "NotFound.html");
    
    app.MapControllerRoute(
        name: "default",
        pattern: "{controller=Home}/{action=Index}/{id?}");
        
    app.Run();

Edit: I've removed the unnecessary class Startup And here is the csproj file:

<Project Sdk="Microsoft.NET.Sdk.Web">

  <PropertyGroup>
    <TargetFramework>net7.0</TargetFramework>
    <Nullable>enable</Nullable>
    <ImplicitUsings>enable</ImplicitUsings>
  </PropertyGroup>

    <ItemGroup>
        <PackageReference Include="Microsoft.AspNetCore.Diagnostics.EntityFrameWorkCore" Version="7.0.11" />
        <PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="7.0.0" />
        <PackageReference Include="Microsoft.EntityFrameWorkCore.SqlServer" Version="7.0.7" />
        <PackageReference Include="Microsoft.EntityFrameWorkCore.Tools" Version="7.0.11">
            <PrivateAssets>all</PrivateAssets>
            <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
        </PackageReference>
        <PackageReference Include="Microsoft.NET.Sdk.Functions" Version="4.2.0" />
        <PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="7.0.7" />
        <PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
        <PackageReference Include="Rotativa.AspNetCore" Version="1.3.2-beta" />
    </ItemGroup>

</Project>

I've checked them several times, I've compared them with the basic application that works, but all I tried didn't work.

I desperately get the following webpage error message:

HTTP Error 403.14 - Forbidden The Web server is configured to not list the contents of this directory.

Most likely causes: A default document is not configured for the requested URL, and directory browsing is not enabled on the server.

Things you can try: If you do not want to enable directory browsing, ensure that a default document is configured and that the file exists. Enable directory browsing using IIS Manager. Open IIS Manager. In the Features view, double-click Directory Browsing. On the Directory Browsing page, in the Actions pane, click Enable. Verify that the configuration/system.webServer/directoryBrowse@enabled attribute is set to true in the site or application configuration file.

Detailed Error Information: Module DirectoryListingModule Notification ExecuteRequestHandler Handler StaticFile Error Code 0x00000000 Requested URL http://localhost:8282/ Physical Path C:\inetpub\wwwroot\NewJoinersWebApp.site Logon Method
Anonymous Logon User Anonymous

More Information: This error occurs when a document is not specified in the URL, no default document is specified for the Web site or application, and directory listing is not enabled for the Web site or application. This setting may be disabled on purpose to secure the contents of the server. View more information ยป

Of course, changing the config in the IIS server to allow the server to list the contents of this directory is not the solution.

The Default Document configuration is the classic one, and in the folder created when publishing the application there no standard files like index.html or default.htm.

It looks like:

The folder created when publishing the application from VS to the IIS server

Is there something I've done wrong, or a thing I missed?

Thanks for any support you could grant.


<?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=".\bin\NewJoinersWebApp.dll" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" hostingModel="inprocess" />
        </system.webServer>
    </location>
</configuration>
1

There are 1 answers

3
samwu On

You can try to enable the Directory Browsing feature to slove this issue:

  1. Start IIS Manager. To do it, select Start, select Run, type inetmgr.exe, and then select OK.
  2. In IIS Manager, expand server name, expand Web sites, and then select the website that you want to change.
  3. In the Features view, double-click Directory Browsing.
  4. In the Actions pane, select Enable.