如何将媒体属性添加到 ASP.NET WebResource.axd Http 处理程序的 CSS LINK html 标记

发布于 2024-08-30 19:15:06 字数 562 浏览 3 评论 0原文

ASP.NET WebResource.axd Http Handler 用于提供嵌入在 DLL 中的资源。

LINK html 标记由 ASP.NET 自动生成。

我想从第三方 DLL 截获一组特定的嵌入式 CSS 的 LINK html 标签的生成,并添加一个媒体属性。

总结:

我想向 ASP.NET WebResource.axd Http 处理程序的 LINK html 标记添加 Media 属性。

所以这样:

<link type="text/css" rel="stylesheet" href="/WebResource.axd?d=XXXXX" />

看起来像这样:

<link media="screen and (min-device-width: 481px)" type="text/css" rel="stylesheet"
 href="/WebResource.axd?d=XXXXX" />

干杯

The ASP.NET WebResource.axd Http Handler is used to serve resources embedded in DLL's.

The LINK html tag is automatically generated by ASP.NET.

I would like to intercept the generation of the LINK html tag for a certain set of embedded CSS from a third party DLL and add a media attribute.

In summary:

I would like to add a Media attribute to the LINK html tag for the ASP.NET WebResource.axd Http Handler.

So this:

<link type="text/css" rel="stylesheet" href="/WebResource.axd?d=XXXXX" />

Appears like this:

<link media="screen and (min-device-width: 481px)" type="text/css" rel="stylesheet"
 href="/WebResource.axd?d=XXXXX" />

Cheers

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

多彩岁月 2024-09-06 19:15:06

有一个解决方法。首先,像这样的链接将被添加到 Page 的头部。您的页面的 标记中必须有 runat=”server” 才能自动包含样式表。 IDE 创建的页面自动具有此设置。因此,添加的链接是 HtmlLink 控件类型。这个想法是迭代 Page 标头中的控件,找到 HtmlLink 控件并设置必要的属性(甚至属性)。我将其包含到 Page_Load 事件中:

Page.Header.Controls
    .OfType<HtmlLink>()
    .ToList()
    .ForEach(link =>
    {
        link.Attributes["media"] = "screen and (min-device-width: 481px)";
    });

在此之前我有:

<head id="Header">
    <title></title>
    <link href="App_Themes/MyTheme/main.css" 
          type="text/css" 
          rel="stylesheet" />
</head>

结果之后是:

我知道,这使用 Themes 代替 WebResource.axd 但对于最后一个结果将是相同的。

最新消息:页面中可能还有其他链接。因此,最好能够识别我们的链接(链接需要修改)。因此,如果没有 id 属性,您可以通过 href 属性识别它们。

There is a workaround. Firstly, links like this are being added to the Page's head. Your page must have runat=”server” in the <head> tag for the automatic style sheet inclusion. The pages created by the IDE have this setting automatically. So, links being added is a HtmlLink control type. The idea is to iterate through controls in Page's header, find HtmlLink controls and set necessary attribute (or even attributes). I include this into the Page_Load event:

Page.Header.Controls
    .OfType<HtmlLink>()
    .ToList()
    .ForEach(link =>
    {
        link.Attributes["media"] = "screen and (min-device-width: 481px)";
    });

Before this I had:

<head id="Header">
    <title></title>
    <link href="App_Themes/MyTheme/main.css" 
          type="text/css" 
          rel="stylesheet" />
</head>

and after the result is:

I know, this uses Themes insted of WebResource.axd but for the last one the result will be the same.

The latest thing: there may be another links in the page. So it would be good to recognize our links (the links need to be modified). So if there is no id attribute you could recognize them by href attribute.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文