【发布时间】:2014-03-28 07:32:24
【问题描述】:
(我是 .Net 和微软世界的新手,来自 Java 和 Tomcat 背景,所以请记住这一点。)
我正在开发我的第一个 .Net 应用程序,使用 Visual Studio 2013、C#、.Net 4.5、MVC 5 和 EF 6。这是一个相当简单的基于 Web 的应用程序,使用 Windows 身份验证和 Active Directory 组进行授权对 SQL Server 数据库中的表执行相当基本的 CRUD 操作。
我还没有部署应用程序。我仍在开发它并在我的 PC(运行 Windows 7)上对其进行测试。当我按下 Ctrl-F5 在 Internet Explorer 或 Google Chrome 中测试应用程序时,一切正常。
但是,如果我告诉 Visual Studio 改为在 Firefox 中访问它,它会显示页面没有任何 CSS 或 JavaScript。我可以单击应用程序中的链接并导航到各个页面,这些页面都可以正常工作。它们只是在没有任何 CSS 或工作 JavaScript 的情况下显示。当我手动尝试查看其中一个 CSS 或 JavaScript 文件时,我收到一个内部服务器错误(HTTP 错误 500)。检查日志文件会显示页面尝试加载的每个 CSS 和 JavaScript 文件的状态代码 500。
我很困惑,因为它可以在 Internet Explorer 和 Chrome 上正常运行。使用不同的网络浏览器怎么会导致这个内部服务器错误?
我会发布一些代码,但此时我不知道看到什么有用。 (如果有的话,我可以显示 IIS Express 正在记录什么样的附加信息,但我不确定在哪里可以找到,除了显示状态代码 500 的行。)
在相当早的开发阶段,我意识到当我希望将某个数据库字段命名为“版本”(大写)时,我已将其命名为“版本”。我在整个解决方案中对该字符串进行了全局查找/替换,而不是对该字段进行重命名。该过程可能会破坏一些重要的事情,但我已经在“版本”(和“版本”)上进行了全局查找,但没有发现任何值得注意的东西。
如果我必须这样做,我可能会从头开始重新创建项目,并希望我不会将相同的问题(或新问题)复制/粘贴到新项目中,但我希望有人可以先想出一些更容易尝试的东西。
更新
这里是 Views/Shared/_Layout.cshtml 的开始:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>@ViewBag.Title - Experiment 626</title>
@Styles.Render("~/Content/css")
@Scripts.Render("~/bundles/modernizr")
</head>
这里是 App_Start\BundleConfig.cs:
using System.Web;
using System.Web.Optimization;
namespace Experiment626
{
public class BundleConfig
{
// For more information on bundling, visit http://go.microsoft.com/fwlink/?LinkId=301862
public static void RegisterBundles(BundleCollection bundles)
{
bundles.Add(new ScriptBundle("~/bundles/jquery").Include(
"~/Scripts/jquery-{version}.js"));
bundles.Add(new ScriptBundle("~/bundles/jqueryval").Include(
"~/Scripts/jquery.validate.min.js",
"~/Scripts/jquery.validate.unobtrusive.min.js"));
// Use the development version of Modernizr to develop with and learn from. Then, when you're
// ready for production, use the build tool at http://modernizr.com to pick only the tests you need.
bundles.Add(new ScriptBundle("~/bundles/modernizr").Include(
"~/Scripts/modernizr-*"));
bundles.Add(new ScriptBundle("~/bundles/bootstrap").Include(
"~/Scripts/bootstrap.js",
"~/Scripts/respond.js"));
bundles.Add(new StyleBundle("~/Content/css").Include(
"~/Content/bootstrap-theme.css",
"~/Content/site.css"));
}
}
}
更新
查看 Firebug,对于每个 CSS 或 JavaScript 文件,请求和响应标头如下所示:
请求标头
GET /Content/site.css HTTP/1.1
Host: localhost:6365
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:27.0) Gecko/20100101 Firefox/27.0
Accept: text/css,*/*;q=0.1
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
DNT: 1
Referer: http://localhost:6365/
Connection: keep-alive
Pragma: no-cache
Cache-Control: no-cache
响应标头
HTTP/1.1 500 Internal Server Error
Cache-Control: private
Content-Type: text/html; charset=utf-8
Server: Microsoft-IIS/8.0
X-SourceFiles: =?UTF-8?B?QzpcVXNlcnNcV2FsbHkuSGFydHNob3JuXFZpc3VhbCBTdHVkaW8gMjAxM1xQcm9qZWN0c1xFeHBlcmltZW50NjI2XEV4cGVyaW1lbnQ2MjZcQ29udGVudFxzaXRlLmNzcw==?=
Persistent-Auth: true
X-Powered-By: ASP.NET
Date: Tue, 25 Feb 2014 21:13:50 GMT
Content-Length: 5870
更新
为了比较,这里是使用 Chrome 时的请求头:
Accept:text/css,*/*;q=0.1
Accept-Encoding:gzip,deflate,sdch
Accept-Language:en-US,en;q=0.8
Cache-Control:no-cache
Connection:keep-alive
Host:localhost:6365
Pragma:no-cache
Referer:http://localhost:6365/
User-Agent:Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.117 Safari/537.36
更新
在 IIS 显示的默认错误页面中,有一个详细的错误信息部分,其中包含以下内容:
Module IIS Web Core
Notification AuthenticateRequest
Handler StaticFile
Error Code 0x80070542
Requested URL http://localhost:6365/Content/site.css
Physical Path C:\Users\Wally.Hartshorn\Visual Studio 2013\Projects\Experiment626\Experiment626\Content\site.css
Logon Method NTLM
Logon User SOMEDOMAIN\Wally.Hartshorn
Request Tracing Directory \\something.domain.com\SPIUsers1\Wally.Hartshorn\IISExpress\TraceLogFiles\EXPERIMENT626
我仍然无法弄清楚如何查看引发状态码 500 的实际异常。
更新
研究该错误代码,我发现它显然意味着“未提供所需的模拟级别,或者提供的模拟级别无效。”我猜有一些关于Firefox 处理身份验证的方式与 Internet Explorer 和 Google Chrome 不同,但我还不知道如何解决这个问题。
更新
作为一个实验,我在 Visual Studio 2013 中创建了一个全新的 ASP.NET MVC 项目,并选择了 Windows 身份验证。然后,在没有对这个全新的解决方案进行 ANY 更改的情况下,我按 Ctrl-F5 来构建它并在 Firefox 中打开默认主页。我在未修改的项目中遇到了完全相同的错误——HTTP 服务器错误 500.0,错误代码为 0x80070542,表示“未提供所需的模拟级别,或者提供的模拟级别无效。”
显然它与我的代码无关,而是我的 Visual Studio 2013、IIS Express 和/或 Windows 7 的配置方式的基本问题。
我被难住了。
【问题讨论】:
-
你可以发布布局标题,或者你在哪里渲染脚本?
-
你试过调试吗?或者至少查看事件查看器(500 是异常,默认情况下将被记录为事件,除非您有一些自定义错误日志记录配置)。
-
您是否尝试过
CTRL+F5强制重新加载页面(在浏览器上) -
火狐控制台说什么?
-
你看过这篇文章吗? stackoverflow.com/questions/847304/…这是另一个可能有用的问题答案:superuser.com/questions/594049/…
标签: .net asp.net-mvc firefox iis static-files