![](/img/trans.png)
[英]GeoJSON file: Refused to execute script from because its MIME type ('') is not executable, and strict MIME type checking is enabled
[英]Angular 6 : Refused to execute script from 'URL' because its MIME type( ) is not executable, & strict MIME type checking is enabled
運行 .net Core Angular 6 SPA 應用程序時出現以下錯誤:
MIME 類型的值為空:
索引.html 文件:
<html lang="en">
<head>
<meta charset="utf-8">
<title>APP</title>
<base href="/">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" type="image/x-icon" href="favicon.ico">
</head>
<body>
<app-root>
<div id="startup-message">
<h1></h1>
<p><span></span></p>
</div>
</app-root>
</body>
</html>
Package.JSON:
Web.Config 文件中添加的客戶標頭:
<customHeaders>
<add name="Access-Control-Allow-Origin" value="*" />
<add name="Access-Control-Allow-Headers" value="Content-Type" />
<add name="Access-Control-Allow-Methods" value="GET, POST, PUT, DELETE, OPTIONS" />
<add name="X-Content-Type-Options" value="nosniff" />
</customHeaders>
我無法重現您的問題。您可以創建一個新的 asp、net core 和 Angular 模板應用程序來檢查問題是否存在並比較文件。
js 文件的 url 很可能是錯誤的。
此外, X-Content-Type option: nosniff
告訴瀏覽器強制加載資源的 MIME。嘗試將其注釋掉。
確保在配置路由之前配置 static 文件。 換句話說,是這樣的:
app.UseHttpsRedirection();
// nb: configure this first!!
app.UseStaticFiles();
if (!env.IsDevelopment())
{
app.UseSpaStaticFiles();
}
app.UseRouting();
app.UseAuthentication();
app.UseAuthorization();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
});
app.UseSpa(spa =>
{
spa.Options.SourcePath = "ClientApp";
spa.Options.StartupTimeout = new TimeSpan(0, 5, 0);
if (env.IsDevelopment())
{
spa.UseAngularCliServer(npmScript: "start");
}
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.