我已经做了一些代码,以返回到网站的博客部分的概述页面。下面代码中的变量OverviewLink1
和OverviewLink2
都是HtmlAnchor
s,并将设置Href
属性等于我所做的变量state
。如何在VB中将对象转换为字符串变量?
属性HttpContext.Current.Application
获取当前HTTP请求的System.Web.HttpApplicationState
对象。
Dim state As HttpApplicationState = HttpContext.Current.Application(component.type & "-" & webId & "-" & langId)
OverviewLink1.HRef = state ' <-- Error happens on this line
OverviewLink2.HRef = HttpContext.Current.Application(component.type & "-" & webId & "-" & langId)
此代码给在第二行上的误差:HttpApplicationState
类型的
值不能被转换为
String
。
第三行不会给出错误。 Try it here in this fiddle.现在我有一些问题:
- 第三条线如何工作?
- 在VB中如何投射一般变量的变量?
- 如何预防这种情况?因为我来自C#,这种情况是不可能的。
我使用VB与ASP.NET Webform (CMS是Liquifi)应用程序。
PS:的由CMS Liquifi使用的变量component.type
,webId
和langId
是变量分别获取组件(类型String
)的名称,该网站的ID (一个网站可以有多个外观)(类型Integer
)和站点(类型Integer
的语言)
更新:
我也试过这个代码
Dim state As String = HttpContext.Current.Application(component.type & "-" & webId & "-" & langId)
OverviewLink1.HRef = state
OverviewLink2.HRef = state
,这工作得很好但是HttpContext.Current.Application
返回HttpApplicationState
而不是字符串,但有一个铸铁发生。为什么?
你确定第三行有效吗? – Pikoh
@Pikoh:是的,我敢肯定,看到小提琴:https://dotnetfiddle.net/deU9N0 –
那个小提琴没有说什么,因为'HttpContext.Current'是'Nothing',所以返回的类型不是'HttpAplicationState' – Pikoh