【发布时间】:2021-05-31 03:23:59
【问题描述】:
我在visual studio community 2019 web app core中创建了一个应用程序,带有角度模板,(代码是您在visual studio中创建应用程序时默认提供的代码)该应用程序使用iis express启动良好,但我需要它在本地 iis 中运行,我已经配置了本地 iis,下载了托管包,但是当我在本地 iis 中运行应用程序时,这发生在我身上,我给你看截图: 这是我的程序.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>();
});
}
}
这是我的 startup.cs
公共类启动 { 公共启动(IConfiguration 配置) { 配置=配置; }
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.AddControllersWithViews();
// In production, the Angular files will be served from this directory
services.AddSpaStaticFiles(configuration =>
{
configuration.RootPath = "ClientApp/dist";
});
}
// 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())
{
app.UseDeveloperExceptionPage();
}
else
{
app.UseExceptionHandler("/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();
if (!env.IsDevelopment())
{
app.UseSpaStaticFiles();
}
app.UseRouting();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllerRoute(
name: "default",
pattern: "{controller}/{action=Index}/{id?}");
});
app.UseSpa(spa =>
{
// To learn more about options for serving an Angular SPA from ASP.NET Core,
// see https://go.microsoft.com/fwlink/?linkid=864501
spa.Options.SourcePath = "ClientApp";
if (env.IsDevelopment())
{
//spa.UseProxyToSpaDevelopmentServer("http://localhost:4200");
spa.UseAngularCliServer(npmScript: "start");
}
});
}
}
i have this version of angular and node
I get this error when I try to run the application in local iis, but in iis express it works fine
But I can access the controller method, it's like it doesn't load angular
有人知道问题出在哪里吗?
【问题讨论】:
-
很难说是什么问题,因为它取决于您的构建/部署。在应用程序的 web.config 文件中启用日志记录并检查日志 - 很可能信息就在其中。
标签: angular visual-studio asp.net-core iis