Visual Studio 2012 SP3 changing link href when usi

2020-06-02 04:58发布

I'm using VS 2012 SP3 in which i have an ASP.NET web site. In my "Default.aspx" i have the following link

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

Whenever i use the design view to for my page like inserting a new row in table in changes it to

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

Which is becoming pretty annoying.

Does anyone have any idea about how to disable this feature ?

I would also like to note that I have Productivity Power Tools 2012 installed Web Essentials 2012 (but i've disabled them both and still not luck Thanks!

Update 1: Steps to reproduce

  • Create a new .aspx page

  • Paste <link href="//netdna.bootstrapcdn.com/twitter-bootstrap/2.3.2/css/bootstrap-combined.min.css" rel="stylesheet" /> between the head tags.

  • Go to split view

  • Write some text between the divs

  • The href changes to <link href="http://localhost:50309/netdna.bootstrapcdn.com/twitter-bootstrap/2.3.2/css/bootstrap-combined.min.css" rel="stylesheet" /> (port may vary :D)

Update 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

2条回答
你好瞎i
2楼-- · 2020-06-02 05:41

The VS designer is picky about URI formats in a link tag, and it will "fix" any href that it does not approve of. The result is not always helpful.

In your case, the issue is that your href is missing a scheme name. VS should stop rewriting your href if you change your link tag like this:

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

Side Note: After you fix the href, the designer may complain that it can't edit the style sheet. I don't know why it does that with this particular file, and I have not seen it do this with other CSS. Just ignore the warning, and the style sheet should be applied correctly.

查看更多
Lonely孤独者°
3楼-- · 2020-06-02 05:47

When using the ASP.NET Script Bundles, you can provide the CDN locations where your script library can be found. When you also add the code locally you get the benefit of being able to debug against the non-minified version while the CDN version will be used when the site runs in production.

See the following documentation on setting up script bundles on ASP.NET Web Forms.

basically you need to add a couple of lines to the Global.asax:

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

And then create your bundle as follows:

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.
}

And reference it like this:

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

This should please both the browser and the editor.


You can also configure the <scriptmanager> to automatically fall back to the CDN using the following pieces of code:

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

And this configuration:

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'"
});

Read the following blog by Scott Hanselman for more details.

查看更多
登录 后发表回答