标识符期望从web.config获取值

时间:2014-01-18 10:59:06

标签: asp.net vb.net

我正在从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

1 个答案:

答案 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