[英]Deploying ASP.NET MVC application on Microsoft IIS server fail
[英]IIS Server MIME Error in ASP.NET MVC Application
大家。
我構建了一個非常簡單的ASP.NET MVC應用程序。 一切正常。 在Visual Studio中從IIS Express運行時,一切正常。
我已經在IIS(Windows 10)上發布了,當我嘗試訪問該應用程序時,在Dev Tools控制台中出現錯誤:
GET http://localhost/Content/css/?v=TkaWEc0q1mz3K1xFKH7PU3OH3FTpfcRL8g5pn-9SziE1 net::ERR_ABORTED 403 (Forbidden)
我檢查了“網絡”選項卡,發現有兩個對Content / css的調用,這是它們的標題:
我一直在研究這個問題,並找到了一些解決方案。 至今:
我的IIS已配置了Static Contant,即使標頭中的Content-Type是text / html(盡管我不明白為什么),IIS中CSS的MIME類型還是text / css。
編輯:如評論中所述,這是我的配置包:
using System.Web;
using System.Web.Optimization;
namespace IoTHub
{
public class BundleConfig
{
public static void RegisterBundles(BundleCollection bundles)
{
bundles.Add(new ScriptBundle("~/bundles/javascript").Include(
"~/Scripts/bootstrap.min.js",
"~/Scripts/jquery-3.3.1.min.js",
"~/Scripts/popper.min.js",
"~/Scripts/iothub.js"));
bundles.Add(new StyleBundle("~/Content/css").Include(
"~/Content/css/bootstrap.min.css",
"~/Content/css/main.css",
"~/Content/css/common.css"));
}
}
}
您可以添加BundleTable.EnableOptimizations = true;
public class MvcApplication : System.Web.HttpApplication
{
protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();
FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
RouteConfig.RegisterRoutes(RouteTable.Routes);
BundleConfig.RegisterBundles(BundleTable.Bundles);
BundleTable.EnableOptimizations = true;
}
}
並檢查web.config設置runAllManagedModulesForAllRequests="true"
<modules runAllManagedModulesForAllRequests="true">
<remove name="BundleModule" />
<add name="BundleModule" type="System.Web.Optimization.BundleModule" />
</modules>
嘗試將其添加到您的網絡配置
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.