如何将媒体属性添加到 ASP.NET WebResource.axd Http 处理程序的 CSS LINK html 标记
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
有一个解决方法。首先,像这样的链接将被添加到
Page
的头部。您的页面的标记中必须有
runat=”server”
才能自动包含样式表。 IDE 创建的页面自动具有此设置。因此,添加的链接是HtmlLink
控件类型。这个想法是迭代Page
标头中的控件,找到HtmlLink
控件并设置必要的属性(甚至属性)。我将其包含到Page_Load
事件中:在此之前我有:
结果之后是:
我知道,这使用
Themes
代替WebResource.axd
但对于最后一个结果将是相同的。最新消息:页面中可能还有其他链接。因此,最好能够识别我们的链接(链接需要修改)。因此,如果没有
id
属性,您可以通过href
属性识别它们。There is a workaround. Firstly, links like this are being added to the
Page
's head. Your page must haverunat=”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 aHtmlLink
control type. The idea is to iterate through controls inPage
's header, findHtmlLink
controls and set necessary attribute (or even attributes). I include this into thePage_Load
event:Before this I had:
and after the result is:
I know, this uses
Themes
insted ofWebResource.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 byhref
attribute.