将版本号附加到 asp:ScriptManager 的合成脚本标记
我们正在尝试让以下场景发挥作用:
我们使用 asp:scriptmanager / CompositeScripts 将脚本组合成几个脚本块,但每次部署到测试系统后,我们都会遇到测试人员无法获取 css 和 javascript 更新版本(浏览器缓存)的问题)。对于 CSS,我们定义了自己的 css 用户控件,它将 Siteversion 参数“?v=1.0.190”附加到 css url 中。此站点版本在 web.config / appsettings 中定义,并在每次部署时都会发生冲突。
我们希望能够对 JavaScript 使用相同的策略,但到目前为止我还没有取得任何成功。 渲染脚本标签时。 Scriptmanager 呈现
<script src="/ScriptResource.axd?d=..." type="text/javascript"></script>
鉴于当前配置的站点版本是 1.0.190,我希望它呈现
<script src="/ScriptResource.axd?d=...&v=1.0.190" type="text/javascript"></script>
如何从脚本管理器获取“script”html 输出以便我可以更改它? 它似乎不存在于 Render、RenderChildren 或 RenderControl 中渲染的内容
中 安德烈亚斯
we are trying to get the following scenario working:
we use asp:scriptmanager / CompositeScripts to combine our scripts into a few script blocks but after each deploy to the test system we have trouble with testers not getting updated versions of css and javascript (browser cache). For the CSS we have defined our own css user control which appends a Siteversion parameter "?v=1.0.190" for instance to the css url. This siteversion is defined in web.config / appsettings and is bumped on every deploy.
We wanted to be able to use the same strategy for javascripts, but thus far I haven't had any success.
When rendering the script tag. the Scriptmanager renders
<script src="/ScriptResource.axd?d=..." type="text/javascript"></script>
Given that the current configured siteversion was 1.0.190, I would want it to render
<script src="/ScriptResource.axd?d=...&v=1.0.190" type="text/javascript"></script>
How do I get at the "script" html output from the script manager so I can change it?
It doesn't seem to be present in the stuff rendered in Render, RenderChildren or RenderControl
Yours
Andreas
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我在反射器中挖掘了一下,不幸的是,这看起来是一个棘手的事情。 MS 没有提供我能找到的任何好的扩展点。但是,如果您愿意采用良好的反射技巧,则为 ScriptManager 添加以下 ControlAdapter 应该可以解决问题:
然后要连接此控制适配器,您将需要创建一个 Web.browser 文件并将其放入您的 App_Browsers 中网站上的文件夹。 Web.browser 文件应该如下所示:
我对此进行了测试,它对我有用。我希望它对你有帮助。
I dug around in reflector for a bit and it looks like this is unfortunately a tricky thing to add. MS didn't provide any good extension points that I could find. However, if you're willing to resort to a nice reflection hack, adding the following ControlAdapter for ScriptManager should do the trick:
Then to hook up this control adapter, you will need to create a Web.browser file and put it in your App_Browsers folder on the website. The Web.browser file should look something like this:
I tested this out and it worked for me. I hope its helpful to you.
页面加载中的一个更简单的解决方案对我来说效果很好:
A much simpler solution in your page's onload works just fine for me:
我会建议一个不同的方法。是你的chache问题,那就改一下cache Header吧。
这是我制作并测试的一个示例,它的工作效果很好。在通话一开始的 global.asax 上......
I will suggest a diferent aproche. The chache is your problem, then change the cache Header.
Here is an example that I make and test it and its works just fine. On the global.asax on the very start of the call...