在设计视图中使用ASP.NET时,Visual Studio 2012 SP3更改链接href

Bob*_*les 13 html c# asp.net visual-studio visual-studio-2012

我正在使用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" />
Run Code Online (Sandbox Code Playgroud)

每当我使用设计视图来为我的页面添加时,就像在表中插入一个新行一样

<link href="http://localhost:50309/netdna.bootstrapcdn.com/twitter-bootstrap/2.3.2/css/bootstrap-combined.min.css" runat="server" rel="stylesheet" />
Run Code Online (Sandbox Code Playgroud)

这变得非常烦人.

有没有人知道如何禁用此功能?

我还要注意,我已经安装了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" />(端口可能有所不同: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

jes*_*ing 3

使用 ASP.NET 脚本包时,您可以提供可找到脚本库的 CDN 位置。当您还在本地添加代码时,您可以获得能够针对非缩小版本进行调试的优势,而当站点在生产中运行时将使用 CDN 版本。

请参阅以下有关在 ASP.NET Web 窗体上设置脚本包的文档

基本上你需要在 Global.asax 中添加几行:

void Application_Start(object sender, EventArgs e)
{
    BundleConfig.RegisterBundles(BundleTable.Bundles);
}
Run Code Online (Sandbox Code Playgroud)

然后按如下方式创建捆绑包:

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.
}
Run Code Online (Sandbox Code Playgroud)

并像这样引用它:

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

这应该会让浏览器编辑器都满意。


您还可以<scriptmanager>使用以下代码将其配置为自动回退到 CDN:

<asp:ScriptManager runat="server" EnableCdn="true">
    <Scripts>
        <asp:ScriptReference Name="jquery" />
        <asp:ScriptReference Name="jquery.ui.combined" />
    </Scripts>
</asp:ScriptManager>
Run Code Online (Sandbox Code Playgroud)

还有这个配置:

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'"
});
Run Code Online (Sandbox Code Playgroud)

请阅读 Scott Hanselman 的以下博客了解更多详细信息