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

前端 未结 2 1403
南旧
南旧 2021-02-07 19:13

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



        
相关标签:
2条回答
  • 2021-02-07 19:53

    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.

    0 讨论(0)
  • 2021-02-07 20:16

    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.

    0 讨论(0)
提交回复
热议问题