有没有办法将对 ASP GetLocalResourceObject 的调用转移到外部静态/共享方法?
我在 ASP 中使用本地资源字符串。我的字符串类似于 “This is a {0}”
我正在使用 String.Format 替换 {0} 值。
无论如何,我想创建一个任何页面都可以调用的静态/共享方法,而不是将此代码放在每个页面中。我原以为我可以传入页面并调用 GetLocalResourceObject()
方法。 GetLocalResourceObject()
受到保护,因此无效。
有没有办法在代码隐藏的外部调用它?
Shared Function GetPatternedResourceString(Byval P as Page, ByVal key As String, ByVal replacement As String) As String
Return String.Format(p.GetLocalResourceObject(key), replacement)
End Function
我意识到还有其他一些方法可以获取本地资源,我认为 HttpContext 上有一种方法,但是您需要做一些额外的工作并传入 url 路径等。
这实际上与此处列出的问题相同 VB.NET:使用 GetLocalResourceObject 的页面的扩展方法
I am using local resource strings in ASP. My strings are something like "This is a {0}"
I am using String.Format to replace the {0} value.
In anycase, rather the put this code in every page, I wanted to create a Static/Shared method that any page could call. I had thought that I could pass the page in and call the GetLocalResourceObject()
method. GetLocalResourceObject()
is protected so its not valid.
Is there a way to call this external to the code-behind?
Shared Function GetPatternedResourceString(Byval P as Page, ByVal key As String, ByVal replacement As String) As String
Return String.Format(p.GetLocalResourceObject(key), replacement)
End Function
I realize there are some other ways to get a local resource, I think there is one on HttpContext but you need to do some extra work and pass in url paths, etc.
This is actually the same problem listed here
VB.NET: Extension method for pages that uses GetLocalResourceObject
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
GetLocalResourceObject()
- 根据指定的 VirtualPath 和 ResourceKey 属性获取页面级资源对象。如需更多说明,您应该阅读此GetLocalResourceObject()
- Gets a page-level resource object based on the specified VirtualPath and ResourceKey properties. For more clarification you should read this