我知道有很多主题都有相同的错误消息,说实话,我尝试了很多,但到目前为止没有一个起作用,这就是我创建这篇文章的原因。
我正在尝试在 IIS 服务器上发布使用 Visual Studio 2022 开发的 .NET 7 Web 应用程序。 我的 IIS 服务器上的配置看起来不错,因为我已经使用一个简单的 Web 应用程序(创建新的 VS 文件后得到的应用程序)对其进行了测试,并且它正在运行。
所以我正在考虑应用程序本身的配置问题。
这是 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 错误 403.14 - 禁止 Web 服务器配置为不列出 该目录的内容。
最可能的原因:未配置默认文档 请求的 URL,并且服务器上未启用目录浏览。
您可以尝试的操作:如果您不想启用目录浏览, 确保配置了默认文档并且该文件存在。 使用 IIS 管理器启用目录浏览。打开 IIS 管理器。在里面 功能视图中,双击目录浏览。在目录上 浏览页面,在操作窗格中单击启用。验证 配置/system.webServer/directoryBrowse@enabled 属性是 在站点或应用程序配置文件中设置为 true。
详细错误信息:模块DirectoryListingModule 通知 ExecuteRequestHandler 处理程序 StaticFile 错误 代码 0x00000000 请求的 URL http://localhost:8282/ 物理 路径 C:\inetpub\wwwroot\NewJoinersWebApp.site 登录方法
匿名登录用户匿名更多信息:未指定文档时会出现此错误 在 URL 中,没有为网站指定默认文档,或者 应用程序,并且未为网站启用目录列表或 应用。可能会故意禁用此设置以保护 服务器的内容。查看更多信息»
当然,更改 IIS 服务器中的配置以允许服务器列出此目录的内容并不是解决方案。
默认文档配置是经典配置,在发布应用程序时创建的文件夹中没有像index.html或default.htm这样的标准文件。
看起来像:
我是否做错了什么,或者错过了什么?
感谢您给予的任何支持。
您可以尝试启用目录浏览功能来解决此问题: