我創建了一個 ASP.NET Core 6 應用程式并將其部署在 IIS 上。我的應用程式作業正常,但是當我進入登錄頁面或任何需要從 SQL Server 獲取資料的頁面時,會顯示錯誤 500。我認為 IIS 和 SQL Server 之間沒有聯系。我該如何解決這個問題?
更新: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 方法來創建資料庫。
uj5u.com熱心網友回復:
試試這個連接字串
"Data Source=(local)\\SQLEXPRESS;Initial Catalog=ArtaCMS;Integrated Security=SSPI;Persist Security Info=True;"
在此之后,您將必須在您的 IIS 上創建一個應用程式池,例如名稱為“ArtaCMS”并選擇“No Managed Code”和“Integrated”并為您的 webapp 選擇池。打開高級設定并選擇“ApplicationPoolIdentity”;
打開 sql server management studio 并添加一個新用戶到您的 ArtaCMS 資料庫,型別為“sql user without login”,名稱為“IIS APPPOOL\ArtaCMS”
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/401350.html
