当我将Net Core 3.1项目发布到Plesk时,出现http 500错误

问题描述

大家好。我正在开发一个具有Net Core 3.1的项目。我通过FTP将项目文件上传到Plesk Panel。我当前的数据是静态的,并且保存在一个类中。我没有在Plesk中创建数据库,但是当我打开网站时,出现HTTP 500错误。我分享了下面可能相关的项目文件。我的项目哪里有错误?你能帮我吗?

当我登录我的网站时 https://imgur.com/SbzyQrt

Startup.cs

 public class Startup
    {
        public Startup(IConfiguration configuration)
        {
            Configuration = configuration;
        }

        public IConfiguration Configuration { get; }

        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            //services.AddDbContext<PropeContext>(options =>
            //{
            //    options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection"));
            //});

            services.AddScoped<IProductRepository,EfCoreProductRepository>();
            services.AddScoped<IProductService,ProductManager>();

            services.AddScoped<ICategoryRepository,EfCoreCategoryRepository>();
            services.AddScoped<ICategoryService,CategoryManager>();

            services.AddControllersWithViews()
                .AddRazorRuntimeCompilation();
            
        }

        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app,IWebHostEnvironment env)
        {
            if (env.IsDevelopment())
            {
                SeedDatabase.Seed();
                app.UseDeveloperExceptionPage();
            }
            else
            {
                //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.UseRouting();

            app.UseAuthorization();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllerRoute(
                  name: "search",pattern: "search",defaults: new { controller = "Product",action = "search" }
                  );

                endpoints.MapControllerRoute(
                   name: "productdetails",pattern: "{url}",action = "details" }
                   );


                endpoints.MapControllerRoute(
                    name: "product",pattern: "products/{category?}",action = "list" }
                    );


                endpoints.MapControllerRoute(
                    name: "default",pattern: "{controller=Home}/{action=Index}/{id?}");
            });
        }
    }

Program.cs

 public class Program
    {
        public static void Main(string[] args)
        {
            CreateHostBuilder(args).Build().Run();
        }

        public static IHostBuilder CreateHostBuilder(string[] args) =>
            Host.CreateDefaultBuilder(args)
                .ConfigureWebHostDefaults(webBuilder =>
                {
                    webBuilder.UseStartup<Startup>();
                    
                });
    }

appsettings.json

{
  //"ConnectionStrings": {
  //  "DefaultConnection": "Server=(localdb)\\MSSQLLocalDB;Database=PropeBoruDB;Trusted_Connection=True;MultipleActiveResultSets=true"
  //},"Logging": {
      "LogLevel": {
        "Default": "Information","Microsoft": "Warning","Microsoft.Hosting.Lifetime": "Information"
      }
    },"AllowedHosts": "*"
  }

SeedDatabase.cs

 public static class SeedDatabase
    {
        public static void Seed()
        {
            var context = new PropeContext();
            if(context.Database.GetPendingMigrations().Count()==0)
            {
                if(context.Categories.Count()==0)
                {
                    context.Categories.AddRange(Categories);
                }
                if (context.Products.Count() == 0)
                {
                    context.Products.AddRange(Products);
                    context.AddRange(ProductCategories);
                }
            }
            context.SaveChanges();
        }
        private static Category[] Categories =
        {
            new Category(){CategoryName="Kategori1",CategoryUrl="kat-egori1"},new Category(){CategoryName="Kategori2",CategoryUrl="kate-gori2"},new Category(){CategoryName="Kategori3",CategoryUrl="kateg-ori3"}
        };
        private static Product[] Products =
       {
            new Product(){ProductName="Ürün1",ProductDesc="Ürün1 açıklama",ProductUrl="urun111",ProductImage="person_1.jpg"},new Product(){ProductName="Ürün2",ProductDesc="Ürün2 açıklama",ProductUrl="urun222",ProductImage="person_2.jpg"},new Product(){ProductName="Ürün3",ProductDesc="Ürün3 açıklama",ProductUrl="urun333",ProductImage="person_3.jpg"},new Product(){ProductName="Ürün4",ProductDesc="Ürün4 açıklama",ProductUrl="urun444",ProductImage="person_4.jpg"},new Product(){ProductName="Ürün5",ProductDesc="Ürün5 açıklama",ProductUrl="urun555",ProductImage="person_5.jpg"}
        };
        private static ProductCategory[] ProductCategories ={
            new ProductCategory(){Product=Products[0],Category=Categories[0]},new ProductCategory(){Product=Products[0],Category=Categories[1]},new ProductCategory(){Product=Products[1],Category=Categories[2]},new ProductCategory(){Product=Products[2],new ProductCategory(){Product=Products[3],Category=Categories[2]}
        };
    }

Context.cs

 public DbSet<Product> Products { get; set; }
        public DbSet<Category> Categories { get; set; }

        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {
            optionsBuilder.UseSqlServer("Server=(localdb)\\MSSQLLocalDB;Database=PropeBoruDB;Trusted_Connection=True;MultipleActiveResultSets=true");
        }
        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            modelBuilder.Entity<ProductCategory>()
                .HasKey(c => new { c.CategoryId,c.ProductId });
        }

launchSetings.json

{
  "iisSettings": {
    "windowsAuthentication": false,"anonymousAuthentication": true,"iisExpress": {
      "applicationUrl": "http://localhost:57306","sslPort": 44307
    }
  },"profiles": {
    "IIS Express": {
      "commandName": "IISExpress","launchBrowser": true,"environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      }
    },"WebApplication13": {
      "commandName": "Project","applicationUrl": "https://localhost:5001;http://localhost:5000","environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"


      }
    }
  }
}

在托管web.config上

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <location path="." inheritInChildApplications="false" allowOverride="false">
    <system.webServer>
      <handlers>
        <add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified" />
      </handlers>
      <aspNetCore processPath="dotnet" arguments=".\WebApplication13.dll" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" hostingModel="inprocess" />
    </system.webServer>
    <system.web>
      <trust level="Full" />
    </system.web>
  </location>
  <system.web>
    <compilation defaultLanguage="c#" />
  </system.web>
  <connectionStrings>
    <remove name="LocalSqlServer" />
  </connectionStrings>
</configuration>
<!--ProjectGuid: 17605A40-B0DB-4151-B6EE-2101A0D4D63D-->

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...