在 IIS 上部署 ASP.NET Core 6 应用程序时出现错误 500(本地主机当前无法处理此请求)

Error 500 when deploying ASP.NET Core 6 application on IIS (localhost is currently unable to handle this request)

我创建了一个 ASP.NET Core 6 应用程序并将其部署在 IIS 上。我的应用程序工作正常,但是当我转到登录页面或任何需要从 SQL 服务器获取数据的页面时,会显示错误 500。我认为 IIS 和 SQL 服务器之间没有 link。我该如何解决这个问题?

更新: appsettings.json:

{
  "Logging": {
    "LogLevel": {
      "Default": "Information",
      "Microsoft.AspNetCore": "Warning"
    }
  },
  "AllowedHosts": "*",
  "ConnectionStrings": {
    "DefaultConnection" : "Server=(local)\SQLEXPRESS;Database=ArtaCMS;Trusted_Connection=True"
  }
}

我使用过身份:

public class IdentityAppContext: IdentityDbContext<AppUser, AppRole, int>
    {
        public IdentityAppContext(DbContextOptions<IdentityAppContext> options) : base(options)
        {

        }
        protected override void OnModelCreating(ModelBuilder builder)
        {
            base.OnModelCreating(builder);
        }
        public DbSet<AppUser> Users { get; set; }
        public DbSet<Message> Messages { get; set; }
        public DbSet<PM> PMs { get; set; }
        public DbSet<Notification> Notifications { get; set; }
        public DbSet<ServiceType> ServiceTypes { get; set; }
        public DbSet<CostCenter> CostCenters { get; set; }
    }

请注意,我的应用程序在 Visual Studio 中运行良好。问题存在于发布中。我使用 Code First 方法创建数据库。

试试这个连接字符串

"Data Source=(local)\SQLEXPRESS;Initial Catalog=ArtaCMS;Integrated Security=SSPI;Persist Security Info=True;"

之后您将必须在您的 IIS 上创建一个应用程序池 例如,名称为“ArtaCMS”和select“无托管代码”和“集成”以及您的网络应用程序的select 池。打开高级设置和 select "ApplicationPoolIdentity";

打开 sql 服务器管理工​​作室并向您的 ArtaCMS 数据库添加一个新用户,类型为“sql 没有登录的用户”,名称为“IIS APPPOOL\ArtaCMS”