You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

ASP.NET MVC4部署至IIS(Win Server2016)后资源加载异常求助

Troubleshooting ASP.NET MVC4 Deployment Issues on Windows Server 2016 IIS

Hey there, let's work through these two common deployment issues step by step—they're totally fixable once you know where to look!

1. IIS Returns Directory Listing Instead of Serving JavaScript Files

This happens when IIS isn't configured to prioritize your application's routing or default documents over directory browsing. Try these fixes:

  • Disable Directory Browsing: Open IIS Manager, select your site, go to the "Directory Browsing" feature in the middle pane, and click "Disable" in the right-hand actions menu. This prevents IIS from showing file lists when it can't find a default entry point.
  • Verify Default Documents: Still in your site's settings, go to "Default Documents" and make sure Default.aspx (the MVC fallback default) is added and positioned at the top. Alternatively, confirm your MVC routes are correctly set to route root requests to Home/Index.
  • Check ASP.NET 4.x Module Installation: Ensure the server has ASP.NET 4.6 (or matching version for MVC4) installed. Go to Server Manager > Add Roles and Features, navigate to Web Server (IIS) > Web Server > Application Development, and check "ASP.NET 4.6". Then verify UrlRoutingModule-4.0 exists in your site's "Modules" list—this is critical for MVC routing to work.
  • Confirm JS File Handler Mapping: In your site's "Handler Mappings", ensure .js files are mapped to the StaticFile handler. If they're mapped to an ASP.NET handler by mistake, IIS will try to parse JS files as server-side code, leading to unexpected behavior.

2. Bundled CSS/JS Fail to Load with "Uncaught SyntaxError: Unexpected token <"

That error almost always means your browser is receiving HTML content (like a 404 error page or directory listing) instead of the expected bundled CSS/JS. Here's how to fix it:

  • Enable Bundle Optimization: In your Global.asax file, make sure you have BundleTable.EnableOptimizations = true; set (usually inside Application_Start()). Debug mode defaults this to false, but production environments need it enabled for IIS to properly serve bundled resources.
  • Install Static Content Feature: IIS needs the Static Content role to serve bundled files. Go to Server Manager > Add Roles and Features, select Web Server (IIS) > Web Server > Common HTTP Features, and check "Static Content". This lets IIS serve merged bundle files as static resources.
  • Double-Check Bundle Paths: In your views, ensure you're using the correct path syntax for bundles, like @Scripts.Render("~/bundles/jquery") and @Styles.Render("~/Content/css"). The ~/ prefix ensures the path resolves correctly relative to your site root—omitting it can lead to broken relative paths and 404s.
  • Verify Application Pool Permissions: The application pool identity for your site needs read access to the server's temporary cache directory where bundles are stored. Set the pool identity to ApplicationPoolIdentity (recommended) and ensure it has read permissions on C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files.
  • Check for Custom Bundle Config Issues: If you're using non-standard file extensions in your bundles or custom bundle transformations, make sure you've added the correct MIME types in IIS (e.g., for .less or .scss files) and that your bundle logic doesn't have typos in file paths.

内容的提问来源于stack exchange,提问作者tatunga23

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.26 09:20:47