【问题标题】:IIS Server MIME Error in ASP.NET MVC ApplicationASP.NET MVC 应用程序中的 IIS 服务器 MIME 错误
【发布时间】:2019-04-11 14:02:57
【问题描述】:

每个人。

我构建了一个非常简单的 ASP.NET MVC 应用程序。它工作正常。在 Visual Studio 中从 IIS Express 运行时,一切正常。

我已在 IIS (Windows 10) 上发布,当我尝试访问应用程序时,我在开发工具控制台中出现错误:

GET http://localhost/Content/css/?v=TkaWEc0q1mz3K1xFKH7PU3OH3FTpfcRL8g5pn-9SziE1 net::ERR_ABORTED 403 (Forbidden)

我检查了我的网络选项卡,发现有两个对 Content/css 的调用,这是它们的标题:

我一直在对这个问题进行一些研究,并找到了一些解决方案。到目前为止:

我的 IIS 配置了静态内容 IIS 中 CSS 的 MIME 类型是 text/css,即使标头中的 Content-Type 是 text/html(我不明白为什么)

编辑:根据 cmets 的要求,这是我的配置包:

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"));
        }
    }
}

【问题讨论】:

  • 你能发布代码行配置包吗?
  • 已编辑,@HienNguyen

标签: c# asp.net asp.net-mvc iis


【解决方案1】:

你可以加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>

【讨论】:

  • 它没有用。我已经进行了更改、构建、发布、使用这些更改重新启动了服务器,并且没有任何不同。
  • 能不能把 new StyleBundle("~/Content/css") 改成 new StyleBundle("~/Content/styles"),你有没有设置编译 debug="false" ?
  • 最后一部分成功了。非常感谢!这肯定会在我的经验教训中。
【解决方案2】:

尝试将此添加到您的网络配置中

<system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/> 
</system.webServer>

【讨论】:

  • 不仅是那个改变,而且它有帮助!谢谢。
猜你喜欢
  • 2017-09-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-10-18
  • 2015-10-09
  • 1970-01-01
  • 1970-01-01
  • 2016-08-17
相关资源
最近更新 更多