I have a problem with an ASP.NET Core web application running on IIS 10. I am developing a single page application using AngularJS.
index.html loads fine, but backend requests don't work with 404 error code in IIS 10. From Visual Studio, it works fine with IIS Express.
Can anyone determine how I can fix the backend requests?
Here is my program.cs
public static void Main(string[] args) { var host = new WebHostBuilder() .UseKestrel() .UseContentRoot(Directory.GetCurrentDirectory()) .UseIISIntegration() .UseStartup<Startup>() .Build(); host.Run(); }
And here is my Configure method from Startup.cs
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory) { app.UseDefaultFiles(); app.UseStaticFiles(); app.UseIdentity(); // Custom middleware for Angular UI-Router app.Use(async (context, next) => { if (!Path.HasExtension(context.Request.Path.Value) && context.Request.HttpContext.Request.Headers["X-Requested-With"] != "XMLHttpRequest" && context.Request.Method.ToUpper() != "POST" && context.Request.Method.ToUpper() != "PUT" && context.Request.Method.ToUpper() != "DELETE") { await context.Response.WriteAsync(File.ReadAllText(env.WebRootPath + "/index.html")); } await next(); }); app.UseMvc(routes => { routes.MapRoute( name: "default", template: "api/{controller=Home}/{action=Index}/{id?}"); }); }
Mate zabo
source share