ASP.NET MVC应用程序提供了在Firefox中看到,只有当内部服务器错误应用程序、错误、服务器、NET

2023-09-03 06:05:29 作者:虐心爱我你怕了么

(我是新来的.Net和微软的世界一般,从Java和Tomcat背景的,所以请记住这一点。)

(I'm new to .Net and the Microsoft world in general, coming from a Java and Tomcat background, so please bear that in mind.)

我的工作我的第一个.NET应用程序,使用Visual Studio 2013年,C#,净4.5,MVC 5和EF 6.这是一个非常简单的基于Web的应用程序,使用Windows身份验证和Active Directory组授权在SQL Server数据库做一个表相当基本的CRUD操作。

I'm working on my first .Net application, using Visual Studio 2013, C#, .Net 4.5, MVC 5, and EF 6. It's a fairly simple web-based application, using Windows authentication and Active Directory groups for authorization to do fairly basic CRUD operations on a table in a SQL Server database.

我还没有部署的应用程序呢。我现在还在开发它,测试它在我的电脑(运行Windows 7)。当我按Ctrl-F5测试在Internet Explorer或谷歌浏览器的应用程序,一切工作正常。

I haven't deployed the application yet. I'm still developing it and testing it out on my PC (running Windows 7). When I hit Ctrl-F5 to test out the application in Internet Explorer or in Google Chrome, everything works fine.

但是,如果我告诉Visual Studio中访问它在Firefox,而是显示在页面的无任何CSS或JavaScript。我可以在应用程序中点击链接和导航到不同的页面,这是所有工作的罚款。他们只是没有显示任何CSS或JavaScript的工作。当我尝试手动查看CSS或JavaScript文件中的一个,我得到一个内部服务器错误(HTTP错误500)。检查日志文件显示状态code 500为每个CSS和JavaScript文件的页面试图加载。

However, if I tell Visual Studio to access it in Firefox instead, it displays the page WITHOUT any CSS or JavaScript. I can click links within the application and navigate to the various pages, which all work fine. They're just displayed without any CSS or working JavaScript. When I manually try to view one of the CSS or JavaScript files, I get an internal server error (HTTP Error 500). Checking the log file shows a status code 500 for each of the CSS and JavaScript files the page was trying to load.

我很迷惑,因为它工作正常,从Internet Explorer和Chrome浏览器。怎么可能使用不同的网络浏览器导致此内部服务器错误?

I'm mystified, because it works fine from Internet Explorer and from Chrome. How could using a different web browser cause this internal server error?

我会发布一些code,但在这一点上我不知道什么是看到有用的。 (我可以显示什么样的附加信息IIS防爆preSS被记录,如果有的话,但我不知道在哪里可以找到,比显示状态code 500线等。)

I'd post some of the code, but at this point I've no idea what would be useful to see. (I could show what sort of additional information IIS Express is logging, if any, but I'm not sure where to find that, other than the line that shows the status code 500.)

在某一点上的发展比较早,我意识到,我已经命名的一些数据库领域的版本时,我想它被命名为版本(大写)。我做了一个全球性的查找/在该字符串的整个解决方案替换,而不是做该领域的重命名。这有可能是一些重要的是通过这个过程borked,但我已经在版本(和版本)做了全局查找,并没有发现值得注意的事情。

At some point fairly early in development, I realized that I had named some database field "version" when I wanted it to be named "Version" (capitalized). I did a global find/replace in the entire solution on that string, rather than doing a rename of the field. It's possible that something important was borked by that process, but I've done a global find on "Version" (and on "version") and haven't found anything of note.

如果我绝对要,我可能就重新从头开始创建项目,并希望我不要复制/粘贴到新的项目同样的问题(或新的),但我希望有人能想出一些更容易先行先试。

If I absolutely have to, I'll probably just re-create the project from scratch and hope that I don't copy/paste the same problem (or a new one) into the new project, but I'm hoping someone can come up with something easier to try first.

下面是浏览的开始/共享/ _Layout.cshtml:

Here is the start of 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:

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

更新

在看萤火虫,每个CSS或JavaScript文件,请求和响应头是这样的:

UPDATE

Looking in Firebug, for each CSS or JavaScript file, the request and response headers look like this:

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时,这里是请求头:

UPDATE

For comparison, here is the request header when using 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

更新

ASP.NET MVC程序发布应用程序

在由IIS显示默认的错误页面,有一个详细的错误信息部分,其中包含这样的:

UPDATE

In the default error page displayed by IIS, there is a Detailed Error Information section, which contains this:

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

我还一直无法弄清楚如何查看时引发触发状态code 500的实际例外。

I still have been unable to figure out how to view the actual exception that is thrown to trigger the status code 500.

研究了错误code,我发现它显然意味着要么未提供所需的模拟级别,或提供的模拟级别无效。我猜有一些关于Firefox的方式处理认证比的方式Internet Explorer和谷歌浏览器的不同,但我不知道还怎么解决这个问题。

Researching that error code, I found that it apparently means "Either a required impersonation level was not provided, or the provided impersonation level is invalid." I'm guessing that there is something about the way Firefox handles authentication that is different than the way Internet Explorer and Google Chrome, but I've no idea yet how to fix that.

作为一个实验,我在Visual Studio 2013中创建了一个全新的ASP.NET MVC项目,选择Windows身份验证。然后,未做任何修改这一全新的解决方案,我按Ctrl-F5来构建它,并在Firefox中打开默认主页。我得到了原封不动的项目完全相同的错误 - HTTP服务器错误500.0,与错误code 0x80070542 ,表示要么未提供所需的模拟级别或所提供的模拟级别是无效的。

As an experiment, I created a brand new ASP.NET MVC project in Visual Studio 2013, selecting Windows Authentication. Then, without making ANY changes to this brand new solution, I hit Ctrl-F5 to build it and open the default Home page in Firefox. I get the exact same error in the untouched project -- HTTP Server Error 500.0, with an error code of 0x80070542, indicating "Either a required impersonation level was not provided, or the provided impersonation level is invalid."

因此​​很明显,它没有任何与我的code,反而是一个基本的问题是如何我的Visual Studio 2013年,IIS防爆preSS,和/或Windows 7配置。

So apparently it has nothing to do with my code, but instead is a basic problem with how my Visual Studio 2013, IIS Express, and/or Windows 7 are configured.

我很为难。

推荐答案

G_P指着我解决我的问题。根本原因显然是,Firefox不与Windows集成身份验证默认的工作,除非该网站是可信的。

G_P pointed me to the solution to my problem. The root cause apparently is that Firefox does not by default work with Windows Integrated Authentication, unless the site is trusted.

要启用Windows集成身份验证在Firefox:

To enable Windows Integrated Authentication in Firefox:

输入有关:在地址栏中配置 确认了可怕的警告信息。 在搜索栏中输入 network.automatic 。 在双击network.automatic-NTLM身份auth.trusted-URI的。 输入服务器的URL,例如本地主机 mycompany.com 。 Enter about:config in the address bar. Acknowledge the scary warning message. In the search bar, enter network.automatic. Double-click on network.automatic-ntlm-auth.trusted-uris. Enter the URL of the server, e.g. localhost or mycompany.com.

在它工作得很好。

不幸的是,这将意味着谁想要访问使用Firefox,他们将不得不作出这个改变(或者IT部门就必须想出一个办法做到这一点),应用程序的公司指导大家。在这个特定的应用程序,这不是什么大不了的事,因为用户的数量将是相当小的。对于以后的应用程序,我可能会找出别的东西。 (或许我应该寻找到Windows身份验证基础?听起来有点吓人,不过。)

Unfortunately, this would mean instructing everyone in the company who wanted to access the application using Firefox that they would have to make this change (or else the IT department would have to figure out a way to do it). In this particular application, that's not a big deal, because the number of users will be quite small. For a later application, I'll probably have to figure out something else. (Perhaps I should be looking into Windows Identity Foundation? Sounds a bit scary, though.)

在任何情况下,我会称之为现在不够好,并与我的生活。由于非常大家谁帮我!

In any case, I'm going to call this "good enough for now" and move on with my life. Thanks very much to everyone who helped me!

P.S。两页具有潜在有用的信息:

P.S. Two pages with potentially useful information:

http://kb.iu.edu/data/atxe.html https://developer.mozilla.org/en-US/docs/Integrated_Authentication http://kb.iu.edu/data/atxe.html https://developer.mozilla.org/en-US/docs/Integrated_Authentication