0
votes

I have created an application in visual studio community 2019 web app core, with angular template, (the code is the one that comes by default when you create an application in visual studio) the application starts well using iis express, but I need it to run in local iis, I have configured the local iis, downloaded the hosting bundle, but when I run the application in local iis this happens to me, I show you screenshots: this is my 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>();
            });
}

}

this is my 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.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

Does anyone know what the problem may be?

1
It's hard to say what the issue is as it depends on your build / deployment. Enable logging in the web.config file of the app and check the logs - most probably the information is in there. - TotallyNewb

1 Answers

0
votes

Have you added both applications under the default website? Or how have you deployed your applications? I do not see CORS setup in your startup file. Also, if you have added your app under default website then you may need to change the base href from "/" to "/applicationName/" or "./applicationName".