我可以修改吗?来自用户控件的 .NET 中的页面部分,不带 runat=“server”?
我的页面没有在 部分中设置 runat="server"。我无权修改页面中的任何代码。
此页面包含我有权访问的用户控件。我可以从用户控件将 标记添加到页面的标题部分吗?它需要在服务器端,因此 JavaScript 解决方案将不起作用。
I have a page that does not have runat="server" set in the <head/>
section. I do not have access to modify any of the code in the page.
This page contains a user control which I do have access to. Can I add a <meta/>
tag to the head section of the page from the user control? It needs to be server-side so a javascript solution won't work.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
一种选择是创建响应过滤器,然后在将输出发送给用户之前修改输出。
https://web.archive.org/web/20211029043851/https://www.4guysfromrolla.com/articles/120308-1.aspx
One option is to create a Response Filter, and then modify the output before it's sent to the user.
https://web.archive.org/web/20211029043851/https://www.4guysfromrolla.com/articles/120308-1.aspx
您可以解析文本
以查看字符串
开始的位置,然后在其中插入所需的任何文本,从而将您自己的代码注入页眉中,而无需使用
runat 进行标记=“服务器”
。但请注意,这是将代码放在最不应该出现的位置的一种非常狡猾的方式(否则
元素将被标记为
runat= “server”
这样就可以正常访问了)。如果稍后将 head 元素更改为 ASP.NET 控件,这也会中断。它可能不适用于母版页,您必须沿着控制树查找最顶层的文字元素。You can parse the text in
to see where the string
<head>
starts, and insert whatever text you need in there thus injecting your own code into the page header without it being marked withrunat="server"
.Please be aware though, this is pretty hacky way of getting your code where it most likely shouldn't be (otherwise the
<head>
element would have been marked asrunat="server"
so you can access it normally). This will also break if at a later date the head element is changed to be an ASP.NET control. It might will not work with master pages, you will have to walk up the control tree looking for topmost literal element.