簡體   English   中英

在設計視圖中使用ASP.NET時,Visual Studio 2012 SP3更改鏈接href

[英]Visual Studio 2012 SP3 changing link href when using ASP.NET in design view

我正在使用VS 2012 SP3,其中我有一個ASP.NET網站。 在我的“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" />

  • 轉到拆分視圖

  • 在div之間寫一些文字

  • href變為<link href="http://localhost:50309/netdna.bootstrapcdn.com/twitter-bootstrap/2.3.2/css/bootstrap-combined.min.css" rel="stylesheet" /> (port可能會有所不同:D)

更新2: Microsoft Bug Report Connect Link

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

使用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撰寫的以下博客, 了解更多詳情

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這樣做。 只需忽略警告,就應該正確應用樣式表。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM