ASP.NET MVC application gives Internal Server Error only when viewed in Firefox
.net, asp.net-mvc, firefox, iis, static-files
Solution
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.
To enable Windows Integrated Authentication in Firefox:
- 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`.
After that it works fine.
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. Two pages with potentially useful information:
- http://kb.iu.edu/data/atxe.html
- https://developer.mozilla.org/en-US/docs/Integrated_Authentication
Problem
(I'm new to .Net and the Microsoft world in general, coming from a Java and Tomcat background, so please bear that in mind.) 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. 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. 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. 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? 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.) 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. UPDATE 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> ``` 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")); } } } ``` UPDATE Looking in Firebug, for each CSS or JavaScript file, the request and response headers look like this: Request Header ``` 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 ``` Response Header ``` 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 ``` 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 ``` 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 ``` I still have been unable to figure out how to view the actual exception that is thrown to trigger the status code 500. UPDATE 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. UPDATE 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." 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. I'm stumped.