13

ASP.NET Web サイトがある VS 2012 SP3 を使用しています。私の「Default.aspx」には、次のリンクがあります

<link href="//netdna.bootstrapcdn.com/twitter-bootstrap/2.3.2/css/bootstrap-combined.min.css" runat="server" rel="stylesheet" />

テーブルに新しい行を挿入するなど、ページにデザインビューを使用するたびに、次のように変更されます

<link href="http://localhost:50309/netdna.bootstrapcdn.com/twitter-bootstrap/2.3.2/css/bootstrap-combined.min.css" runat="server" rel="stylesheet" />

これはかなり面倒です。

この機能を無効にする方法を知っている人はいますか?

また、Productivity Power Tools 2012 を Web Essentials 2012 にインストールしていることにも注意したいと思います (ただし、両方を無効にしましたが、まだうまくいきません。ありがとう!

更新 1: 再現手順

  • 新しい .aspx ページを作成する

  • <link href="//netdna.bootstrapcdn.com/twitter-bootstrap/2.3.2/css/bootstrap-combined.min.css" rel="stylesheet" />head タグの間に貼り付けます。

  • 分割ビューに移動

  • divの間にテキストを書きます

  • href が次のように変更され<link href="http://localhost:50309/netdna.bootstrapcdn.com/twitter-bootstrap/2.3.2/css/bootstrap-combined.min.css" rel="stylesheet" />ます (ポートは異なる場合があります:D)

更新 2: Microsoft Bug Report Connect リンク

https://connect.microsoft.com/VisualStudio/feedback/details/793557/visual-studio-2012-ching-link-href-when-using-asp-net-in-design-view#details

4

2 に答える 2

3

ASP.NET スクリプト バンドルを使用する場合、スクリプト ライブラリがある CDN の場所を指定できます。また、コードをローカルに追加すると、縮小されていないバージョンに対してデバッグできるという利点が得られますが、サイトが運用環境で実行されるときに CDN バージョンが使用されます。

ASP.NET Web フォームでのスクリプト バンドルの設定については、次のドキュメントを参照してください。

基本的に、Global.asax に数行追加する必要があります。

void Application_Start(object sender, EventArgs e)
{
    BundleConfig.RegisterBundles(BundleTable.Bundles);
}

次に、次のようにバンドルを作成します。

public static void RegisterBundles(BundleCollection bundles)
{
    //bundles.Add(new ScriptBundle("~/bundles/jquery").Include(
    //            "~/Scripts/jquery-{version}.js"));

    bundles.UseCdn = true;   //enable CDN support

    //add link to jquery on the CDN
    var jqueryCdnPath = "http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.7.1.min.js";

    bundles.Add(new ScriptBundle("~/bundles/jquery",
                jqueryCdnPath).Include(
                "~/Scripts/jquery-{version}.js"));

    // Code removed for clarity.
}

そして、次のように参照します。

<asp:PlaceHolder runat="server">        
     <%: Scripts.Render("~/bundles/modernizr") %>
     <%: Scripts.Render("~/bundles/jquery") %>
     <%: Scripts.Render("~/bundles/jqueryui") %>
</asp:PlaceHolder>

これは、ブラウザエディタの両方を喜ばせるはずです。


<scriptmanager>次のコードを使用して、CDN に自動的にフォールバックするように を構成することもできます。

<asp:ScriptManager runat="server" EnableCdn="true">
    <Scripts>
        <asp:ScriptReference Name="jquery" />
        <asp:ScriptReference Name="jquery.ui.combined" />
    </Scripts>
</asp:ScriptManager>

そして、この構成:

var mapping = ScriptManager.ScriptResourceMapping;
// Map jquery definition to the Google CDN
mapping.AddDefinition("jquery", new ScriptResourceDefinition
{
    Path = "~/Scripts/jquery-2.0.0.min.js",
    DebugPath = "~/Scripts/jquery-2.0.0.js",
    CdnPath = "http://ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js",
    CdnDebugPath = "https://ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.js",
    CdnSupportsSecureConnection = true,
    LoadSuccessExpression = "window.jQuery"
});

// Map jquery ui definition to the Google CDN
mapping.AddDefinition("jquery.ui.combined", new ScriptResourceDefinition
{
    Path = "~/Scripts/jquery-ui-1.10.2.min.js",
    DebugPath = "~/Scripts/jquery-ui-1.10.2.js",
    CdnPath = "http://ajax.googleapis.com/ajax/libs/jqueryui/1.10.2/jquery-ui.min.js",
    CdnDebugPath = "http://ajax.googleapis.com/ajax/libs/jqueryui/1.10.2/jquery-ui.js",
    CdnSupportsSecureConnection = true,
    LoadSuccessExpression = "window.jQuery && window.jQuery.ui && window.jQuery.ui.version === '1.10.2'"
});

詳細については、Scott Hanselmanによる次のブログを参照してください

于 2013-07-11T19:29:09.673 に答える
2

VS デザイナーは、リンク タグの URI 形式にうるさいので、承認しない href を「修正」します。結果は常に役立つとは限りません。

あなたの場合、問題は、href にスキーム名がないことです。次のようにリンクタグを変更すると、VS は href の書き換えを停止する必要があります。

<link href="http://netdna.bootstrapcdn.com/twitter-bootstrap/2.3.2/css/bootstrap-combined.min.css" rel="stylesheet" type="text/css" />

補足: href を修正した後、デザイナーはスタイル シートを編集できないと文句を言うかもしれません。なぜこの特定のファイルでそれを行うのかわかりません。また、他の CSS でこれを行うのを見たことがありません。警告を無視するだけで、スタイル シートが正しく適用されます。

于 2013-07-29T03:10:56.900 に答える