【发布时间】:2016-05-04 15:08:48
【问题描述】:
这是我的简单用户名和密码登录,它能够将用户重定向到不同的“会员区”页面。
但是我得到一个:
BC32045:“System.Collections.IEnumerable”没有类型参数,因此不能有类型参数
我也不知道为什么。
有人可以帮忙吗?
谢谢,大卫。
Public Class MyPage
Inherits Page
Private Structure Cred
Public Username As String
Public Password As String
Public RedirectUrl As String
Public Sub New(un As String, pw As String, Optional ru As String = "/admin/default.aspx")
Username = un
Password = pw
RedirectUrl = ru
End Sub
End Structure
Private ReadOnly _credentials As IEnumerable(Of Cred) = New () {New Cred("userone", "passwordone"), New Cred("usertwo", "passwordtwo"), New Cred("userthree", "passwordthree", "/admin/custom.aspx")}
Public Sub Page_Load(sender As Object, e As EventArgs)
Dim user = _credentials.SingleOrDefault(Function(x) x.Username = UserName.Text AndAlso x.Password = Password.Text)
If user IsNot Nothing Then
Session("Admin") = True
Response.Redirect(user.RedirectUrl)
Else
Session("Admin") = False
LtlLogin.Text = "<p>Sorry, you have provided incorrect login details.</p>"
End If
End Sub
End Class
【问题讨论】:
-
你从哪里得到它?
-
@TimSchmelter 在这一行: Private ReadOnly _credentials As IEnumerable(Of Cred) = New () {New Cred("userone", "passwordone"), New Cred("usertwo", "passwordtwo" ), New Cred("userthree", "passwordthree", "/admin/custom.aspx")}
-
您可能在某处导入 System.Collections 而不是 System.Collections.Generic。
-
错误很明显,因为@Craig 表明
IEnumerable<T>驻留在命名空间System.Collections.Generic中。您的编译器错误告诉您它找到了类型System.Collections.IEnumerable,它没有类型参数。你错过了Imports System.Collections.Generic。 -
@CraigH 谢谢克雷格,但是所有这一切都只是我的头脑......关于如何重组我的代码以便它可以工作的任何想法?谢谢。大卫。
标签: asp.net vb.net passwords ienumerable credentials