每个人。
我构建了一个非常简单的 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(我不明白为什么)
编辑:正如评论中所问,这是我的配置包:
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>
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句