【问题标题】:Error when publishing .net core app "no startup configured "发布 .net 核心应用程序“未配置启动”时出错
【发布时间】:2019-02-20 13:51:42
【问题描述】:

两天以来,当我在 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>();
}

文件中的日志://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本地逐行调试,看看哪个服务有异常,添加到你的问题中
  • 所有本地工作:/
  • 你是如何发布你的项目的?创建和发布新的默认 mvc 模板时是否存在问题?
  • 嗨@Q.Rey,你是如何解决这个错误的,请给出答案。我有 2 台电脑,其中一台在本地运行,但在另一台电脑上出现错误。

标签: c# asp.net-core


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-04-16
    • 1970-01-01
    • 2014-12-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多