我在IIS 10上运行的ASP.NET Core Web应用程序出现问题。 我正在开发一个带有AngularJS的单页面应用程序。IIS 10上的ASP.NET核心404错误
index.html完美加载,但后端请求在IIS 10上出现404错误代码时失败。从使用IIS Express的Visual Studio中,它完美地工作。
任何人都可以知道我该如何修复后端请求?
这里是我的Program.cs
public static void Main(string[] args)
{
var host = new WebHostBuilder()
.UseKestrel()
.UseContentRoot(Directory.GetCurrentDirectory())
.UseIISIntegration()
.UseStartup<Startup>()
.Build();
host.Run();
}
下面是从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?}");
});
}
启用ASP.NET Core日志记录(可能带有调试日志级别),并查看是否有任何消息说明此失败原因 –
也发布了web.config。 –
你配置了MVC服务吗? –