简体   繁体   English

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

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

I'm using VS 2012 SP3 in which i have an ASP.NET web site. 我正在使用VS 2012 SP3,其中我有一个ASP.NET网站。 In my "Default.aspx" i have the following link 在我的“Default.aspx”中,我有以下链接

<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! 我还要注意,我已经安装了Productivity Power Tools 2012 Web Essentials 2012(但我已经禁用了它们,但仍然没有运气谢谢!

Update 1: Steps to reproduce 更新1: 重现的步骤

  • Create a new .aspx page 创建一个新的.aspx页面

  • Paste <link href="//netdna.bootstrapcdn.com/twitter-bootstrap/2.3.2/css/bootstrap-combined.min.css" rel="stylesheet" /> between the head tags. 在头标记之间粘贴<link href="//netdna.bootstrapcdn.com/twitter-bootstrap/2.3.2/css/bootstrap-combined.min.css" rel="stylesheet" />

  • Go to split view 转到拆分视图

  • Write some text between the divs 在div之间写一些文字

  • 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) href变为<link href="http://localhost:50309/netdna.bootstrapcdn.com/twitter-bootstrap/2.3.2/css/bootstrap-combined.min.css" rel="stylesheet" /> (port可能会有所不同:D)

Update 2: Microsoft Bug Report Connect Link 更新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 https://connect.microsoft.com/VisualStudio/feedback/details/793557/visual-studio-2012-changing-link-href-when-using-asp-net-in-design-view#details

When using the ASP.NET Script Bundles, you can provide the CDN locations where your script library can be found. 使用ASP.NET脚本包时,您可以提供可以找到脚本库的CDN位置。 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. 当您还在本地添加代码时,您将获得能够针对非缩小版本进行调试的好处,而当站点在生产中运行时将使用CDN版本。

See the following documentation on setting up script bundles on ASP.NET Web Forms . 请参阅以下有关在ASP.NET Web窗体上设置脚本包的文档

basically you need to add a couple of lines to the Global.asax: 基本上你需要在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: 您还可以使用以下代码配置<scriptmanager>自动回退到CDN:

<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 . 阅读Scott Hanselman撰写的以下博客, 了解更多详情

The VS designer is picky about URI formats in a link tag, and it will "fix" any href that it does not approve of. VS设计师对链接标记中的URI格式很挑剔,它会“修复”它不赞同的任何href。 The result is not always helpful. 结果并不总是有用。

In your case, the issue is that your href is missing a scheme name. 在您的情况下,问题是您的href缺少方案名称。 VS should stop rewriting your href if you change your link tag like this: 如果您更改链接标记,VS应该停止重写您的href:

<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. 侧注:修复href后,设计人员可能会抱怨它无法编辑样式表。 I don't know why it does that with this particular file, and I have not seen it do this with other CSS. 我不知道为什么它使用这个特定的文件,我还没有看到它与其他CSS这样做。 Just ignore the warning, and the style sheet should be applied correctly. 只需忽略警告,就应该正确应用样式表。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM