Home > OS >  Error 500 when deploying ASP.NET Core 6 application on IIS (localhost is currently unable to handle
Error 500 when deploying ASP.NET Core 6 application on IIS (localhost is currently unable to handle

Time:01-02

I have created an ASP.NET Core 6 application and deployed it on IIS. My application works fine but when I go to login page, or any page that needs to get data from SQL Server, Error 500 is shown. I think there is no link between IIS and SQL Server. How can I fix this problem?

Update: appsettings.json:

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

I have used Identity:

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

Note that my App works fine in Visual Studio. The problem exists in publish. I have used Code First approach to create database.

CodePudding user response:

try this connection string

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

after this you will have to create an application pool at your IIS for example with name "ArtaCMS" and select "No Managed Code" and "Integrated" and select pool for your webapp. Open advanced setting and select "ApplicationPoolIdentity";

Open sql server management studio and add a new user to your ArtaCMS database with type "sql user without login" and name "IIS APPPOOL\ArtaCMS"

  • Related