【问题标题】:Is there a way to move a call to ASP GetLocalResourceObject to a external static/shared method?有没有办法将对 ASP GetLocalResourceObject 的调用移动到外部静态/共享方法?
【发布时间】:2011-05-18 20:49:03
【问题描述】:

我在 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: Extension method for pages that uses GetLocalResourceObject

【问题讨论】:

    标签: asp.net oop resources


    【解决方案1】:

    GetLocalResourceObject() - 根据指定的 VirtualPath 和 ResourceKey 属性获取页面级资源对象。如需更多说明,请阅读this

    【讨论】:

      猜你喜欢
      • 2013-04-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-11-28
      • 1970-01-01
      • 2020-03-06
      • 2013-08-21
      • 2011-03-24
      相关资源
      最近更新 更多