You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

.NET 7 Web应用部署IIS出现HTTP Error 403.14错误求助

发布.NET 7 MVC应用到IIS时出现403.14禁止访问错误

已查阅大量相同错误的讨论,尝试多种方案均未解决,特此求助。我使用Visual Studio 2022开发了一个.NET 7 MVC Web应用,尝试发布到IIS服务器时遇到问题。IIS已通过简单应用测试确认配置正常,因此判断问题出在应用自身配置上。

Program.cs代码

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();

编辑说明:已移除多余的class Startup

csproj文件内容

<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>

错误信息

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.

允许目录列表并非解决方案,IIS默认文档配置正常,但发布文件夹中没有index.html等标准静态文件,文件夹结构如下:

发布到IIS的应用文件夹结构

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

请问是否存在操作失误或遗漏的配置?感谢帮助。


内容的提问来源于stack exchange,提问作者Hakeem

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.27 09:47:32