我正在从web.config读取值,并希望将用户重定向到我的web.config中的url。但是当我尝试访问密钥时,这给了我identifier expected
的错误。下面是我的web.config和代码部分。能否请你解释一下我在这里做错了什么。
<appSettings>
<add key="SECURE_URL" value="https://google.com"/>
</appSettings>
这是我的代码
Protected Sub bttSearch1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles bttSearch1.Click
Dim StrValue As String = System.Configuration.ConfigurationManager.AppSettings["SECURE_URL"]
Response.Redirect("StrValue" + "/park/notice/payment.aspx")
End Sub
答案 0 :(得分:4)
当您使用VB.NET时,不使用方括号([“SECURE_URL”])来访问索引,而是使用普通括号((“SECURE_URL”)),因此您需要更改以下行
Dim StrValue As String = System.Configuration.ConfigurationManager.AppSettings["SECURE_URL"]
向
Dim StrValue As String = System.Configuration.ConfigurationManager.AppSettings("SECURE_URL")
这将解决编译错误;但是,为了使您的样本有效,您还应该更改以下行
Response.Redirect("StrValue" + "/park/notice/payment.aspx")
要
Response.Redirect(StrValue + "/park/notice/payment.aspx")
这样,使用了StrValue
的值
此外,在使用其值之前,您应检查StrValue
是否为Nothing(null)或为空,即:
If Not String.IsNullOrEmpty(StrValue) Then
Response.Redirect(StrValue + "/park/notice/payment.aspx")
End If