我在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服務嗎? –