是否可以覆盖 ResolveUrl?
我使用以下 .net 应用程序来解析图像、CSS 文件或 JavaScript 文件的路径。
<%=ResolveUrl("~/Scripts/myscript.js")%>
<%=ResolveUrl("~/images/myimage.jpg")%>
我的所有页面和控件都继承自基本页面或基本用户控件。
我已经尝试过,但没有成功覆盖 ResolveUrl 方法,以便我可以在文件路径中包含一些自定义逻辑。
有什么想法可以重写 ResolveUrl 方法吗?另一种方法是创建我自己的自定义方法,其功能类似,但更喜欢与 ResolveUrl 一起使用。
I use the following my .net applications to resolve the path to an image or css file or javascript file.
<%=ResolveUrl("~/Scripts/myscript.js")%>
<%=ResolveUrl("~/images/myimage.jpg")%>
All my pages and controls inherit from a base page or base user control.
I have tried but didnt succeed in overriding the ResolveUrl method so that I could include some custom logic in the files path.
Any ideas how I might override the ResolveUrl method? Alternative is to create my own custom method that does similar but would prefer to work with ResolveUrl.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
ResolveUrl
不是虚拟的,因此使用覆盖几乎不会成功,并且它不会在内部使用您可以覆盖的任何内容来自定义功能。这样您就可以编写自己的实用函数了。ResolveUrl
is not virtual so you will have little success using an override and it does not internally use anything that you can override to customize the functionality. That leaves you with writting your own utility function.我会创建您自己的
ResolveCustomUrl
方法,这样未来的开发人员就不会发疯I would create your own
ResolveCustomUrl
method so that future developers don't go crazy