gpt4 book ai didi

c# - 发布 .net 核心应用程序时出错 "no startup configured "

转载 作者:行者123 更新时间:2023-12-03 17:30:40 26 4
gpt4 key购买 nike

两天以来,当我在 IIS 上发布我的 .net 核心应用程序时发生错误。
我的角度部分运行良好,但 .net 核心部分无法加载。

在我的 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.AddCors();
services.AddDbContext<HistoriqueContext>(options =>
options.UseSqlServer(Configuration.GetConnectionString("HistoriqueContext"),b=>b.UseRowNumberForPaging()));
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);

}

// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
app.UseCors(builder => builder
.WithOrigins("http://localhost:4200")
.AllowAnyMethod()
.AllowAnyHeader()
.AllowCredentials());
app.UseAuthentication();

app.Use(async (context, next) =>
{
await next();
if (context.Response.StatusCode == 404 && !Path.HasExtension(context.Request.Path.Value))
{
context.Request.Path = "/index.html";
await next();
}
});

app.UseStaticFiles();
//app.UseCorsMiddleware();
app.UseMvc();
}
}`

在我的 Program.cs 中:
 public class Program
{
public static void Main(string[] args)
{
CreateWebHostBuilder(args).Build().Run();
}

public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>();
}

在 file://servername/appcore/logs/中的日志:
Application startup exception: System.InvalidOperationException: No startup configured. Please specify startup via WebHostBuilder.UseStartup, WebHostBuilder.Configure, injecting IStartup or specifying the startup assembly via StartupAssemblyKey in the web host configuration.
at Microsoft.AspNetCore.Hosting.Internal.WebHost.EnsureStartup()
at Microsoft.AspNetCore.Hosting.Internal.WebHost.EnsureApplicationServices()
at Microsoft.AspNetCore.Hosting.Internal.WebHost.Initialize()
--- End of stack trace from previous location where exception was thrown ---
at Microsoft.AspNetCore.Hosting.Internal.WebHost.BuildApplication()
Hosting environment: Production
Content root path: C:\inetpub\wwwroot\DSMHistory
Now listening on: http://127.0.0.1:38556
Application started. Press Ctrl+C to shut down.
Application is shutting down...

如果有人有同样的问题告诉我,谢谢关注

最佳答案

我遇到了同样的问题,结果我在 Startup.cs 构造函数中发生了一个方法调用,该调用引发了异常并导致了这个确切的错误。

关于c# - 发布 .net 核心应用程序时出错 "no startup configured ",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54787962/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com