1

In my ASP.NET MVC application I'm adding CSS and JavaScript files in the following way:

@Script.AddCss("~/Content/css/style2.css", siteWide: true)
@Script.AddCss("~/Content/css/tipsy.css", siteWide: true)

@Script.AddJavaScript(localPath: "~/Content/js/modernizr-2.5.3.js", siteWide: true)
@Script.AddJavaScript(localPath: "~/Content/js/jquery/jquery.datatables.js", siteWide: true)

And the output looks like the following:

@Script.OutputCss()

And almost the same for JavaScript:

@Script.OutputJavaScript()

Then the template engine combines all the files into AXD files and puts into the source of the page preserving the content-type.

This works fine in all browser but not in IE9. Sometimes the stylesheets are not being loaded and the following error message appears in the console:

SEC7113: CSS was ignored due to mime type mismatch 
scripts.axd?type=Stylesheet&hash=74A0F67DE9D74AFCDAE1AA539EA11099

Besides of that, when you look into the Network tab, the AXD files are being loaded twice - 2 AXD files for the CSS and 2 AXD files for JavaScript. One of each file weights 0 bytes. This happens not always but only sometimes, too often though.

Could anybody help me with an advise on where the problem can be?

Thank you beforehand.

4

2 に答える 2

2

MIME タイプの不一致が原因で、つまり 9 と 10 では css が無視されました。MIME タイプはFIle TypesManというユーティリティで修正できます。これは NirSoft によって作成されたフリーウェアです。.css の MIME タイプが text/plain に変更されており、スタイルをレンダリングできないことが判明しました。FileTypesMan を使用して text/css に戻すと、問題が修正されました。

  1. FileTypesMan を NirSoft サイトからダウンロードします。ページの下部にあるリンクを使用して、お使いのオペレーティング システムに適したバージョンを選択してください (32 ビット、64 ビット、および Windows 98/ME にはさまざまなバージョンがあります)。
  2. ファイルをローカル フォルダーに解凍し、FileTypesMan.exe をダブルクリックします。
  3. FileTypesMan がすべてのファイル タイプの一覧表示を終了したら、上部ペインを下にスクロールして .css を見つけます。
  4. ダブルクリックして設定を編集します。
  5. 開いたダイアログ ボックスの [MIME タイプ] フィールドで、値を text/css に変更します。
  6. [OK] をクリックします。ジョブ完了。IE 10 は、それ自体で動作するはずです (少なくとも、レンダリング スタイル シートに関する限り)。
于 2013-09-13T17:23:08.567 に答える
-2

IE9 では、元のページが信頼済みゾーンにない場合、クロスドメイン スタイルシートに text/CSS MIME タイプが必要です。信頼されたゾーンにある場合、text/CSS MIME がなくても機能するはずです。これが、問題が時々発生する理由です。

そのため、ContentType 宣言がページ ディレクティブに存在することを確認してください。

<%@ Page Language="C#" ContentType="text/css" %> 

それが問題だったことを願っています。

于 2012-09-11T20:20:37.387 に答える