两天以来,当我在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>();
}
文件://服务器名/ 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...
如果有人遇到相同的问题,请告诉我
答案 0 :(得分:0)
我遇到了同样的问题,结果我在 Startup.cs 构造函数中发生了一个方法调用,该调用引发了异常并导致了这个确切的错误。