Error BC30311 after modifying source

  • Thread starter Thread starter Dan Lewis
  • Start date Start date
D

Dan Lewis

Apologies up front if this is a simple thing, but I'm slowly learning
vb .net with a background in vbscript (much simpler!). I have a web
app that I'm trying to modify. The .aspx.vb file in question allows a
new user (orgzuser) to register and the user object is defined with
the code shown below. I'm trying to modify the code so that the users
are created (added to the associated database) with two roles
automatically (groupid of 1 and 4). Sounds simple, but I can't get it
to work because I'm not understanding the data types. From reading
the source files, I thought the datatype was integer (it is in the
database), but because the user object is a defined item (sorry if the
terminology is not correct), it appears to be a "special" datatype (in
vbscript, everything is basically text).

Here's the orgzuser class:


Imports System.Security.Principal
Namespace Orgz
Public Class OrgzUser
Implements System.Security.Principal.IPrincipal

'********************************************************************************************************
'Purpose: Special user class that extends the IPrincipal
object to allow for our custom role interface.

'********************************************************************************************************
Private _identity As IIdentity
Private _roles() As String
Public ReadOnly Property Identity() As
System.Security.Principal.IIdentity Implements
System.Security.Principal.IPrincipal.Identity
Get
Return _identity
End Get
End Property

Public Sub New(ByVal identity As IIdentity, ByVal roles() As
String)
_identity = identity
_roles = roles
roles.CopyTo(_roles, 0)
Array.Sort(_roles)
End Sub

Public Function IsInRole(ByVal role As String) As Boolean
Implements System.Security.Principal.IPrincipal.IsInRole
Return (IIf(Array.BinarySearch(_roles, role) >= 0, True,
False))
End Function

End Class

End Namespace




Here is the registration.aspx.vb. The change I made is shown with ***
in the comments. Right now, I get an error of BC30311 (incorrect
datatype):

Imports System.Collections
Imports System.DirectoryServices

Namespace netconnector

Partial Class registration
Inherits System.Web.UI.Page

#Region " Web Form Designer Generated Code "

'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()

End Sub
Protected WithEvents Panel1 As System.Web.UI.WebControls.Panel
Protected WithEvents pnlPreFill As System.Web.UI.WebControls.Panel
Protected WithEvents btnQuery As
System.Web.UI.WebControls.LinkButton


Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form
Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub

#End Region


#Region " Page Related Code "

'********************************************************************************************************
'Name: Page_Load
'Parameters:
' sender - The object calling the function, i.e. the page
' e - event arguments
'Returns: Nothing
'Purpose: To do startup activities when the page loads for the
first time. Binding data to the datagrid
' Binding data to the dropdowns, setting visibility.

'********************************************************************************************************
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
If Not (IsNothing(Session)) And Response.IsClientConnected
Then
Dim user As New Orgz.User
user.txtusername = user.getuseridbyusername()
If (user.GetUserExistence() <= 0) Then
If
UCase(ConfigurationManager.AppSettings("authentication")) <> "FORMS"
Then
lblusername.Visible = False
lblpassword.Visible = False
txtusername.Visible = False
txtpassword.Visible = False
Else
lblusername.Visible = True
lblpassword.Visible = True
txtusername.Visible = True
txtpassword.Visible = True
End If
If Not IsPostBack Then
Dim installation As New Orgz.Installation

pnlform.Visible = True
pnlresult.Visible = False
If
UCase(ConfigurationManager.AppSettings("authentication")) = "DOMAIN"
Then
'FillForm()
End If

End If
Else
lblresult.Text = "You have already registered for the
system. Please check back later after you have been approved for
access."
pnlform.Visible = False
pnlresult.Visible = True
End If
Else
Server.Transfer("~/errors/sessiontimeout.apsx", False)
End If
End Sub
#End Region

#Region " Datagrid Related Code "

#End Region

#Region " Other Event Procedures "



'********************************************************************************************************
'Name: lnkAdd_Click
'Parameters:
' sender - The object calling the function, i.e. lnkAdd
' e - event arguments
'Returns: Nothing
'Purpose: Adds a user to the database.

'********************************************************************************************************
Private Sub lnkAdd_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles lnkAdd.Click
lnkAdd.Enabled = False
Dim user As New Orgz.User
Dim roles As New System.Collections.Generic.List(Of
Orgz.Role)


Dim map As New Orgz.Map

'add ***
roles.add("1")
roles.add("4")
'end add ***

user.txtusername = user.getuseridbyusername()
If (user.GetUserExistence() <= 0) Then
If
UCase(ConfigurationManager.AppSettings("authentication")) = "FORMS"
Then
user.txtusername = txtusername.Text
user.txtpassword = txtpassword.Text
Else
Dim username As String = String.Empty
username = user.getuseridbyusername()
If username.Length < 1 Then
Throw New Exception("Problem getting
certificate for" & txtfname.Text & " " & txtlname.Text)
End If
user.txtusername = user.getuseridbyusername()
user.txtpassword = "NOPASSWORDHERE"
End If
user.txtfirstname =
Orgz.Functions.scrubinput(txtfname.Text)
user.txtlastname =
Orgz.Functions.scrubinput(txtlname.Text)
user.txtrank = Orgz.Functions.scrubinput(txtrank.Text)
user.txtsquadron =
Orgz.Functions.scrubinput(txtsquadron.Text)
user.txtoffice =
Orgz.Functions.scrubinput(txtoffice.Text)
user.txtwing = Orgz.Functions.scrubinput(txtwing.Text)
user.txtinstallation =
IIf(IsNothing(dpdinstallation.SelectedItem.Value), 0,
dpdinstallation.SelectedItem.Value)
user.txtemail =
Orgz.Functions.scrubinput(txtemail.Text)
user.txtphone =
Orgz.Functions.scrubinput(txtphone.Text)
user.defaultmap = map.GetDefaultMap()
user.txtnotes = ""

user.bolactivated = 1

user.dtepassexpire = DateAdd(DateInterval.Day, 365,
Now())


user.roles = roles

user.dtedateactivated = Now()
user.dtedatecreated = Now()

user.adduser()

lblresult.Text = "You have been successfully
registered. You will recieve an email at your specified e-mail
address when your account has been activated."
sendmail()
Else
pnlresult.Visible = True
pnlPreFill.Visible = False
pnlform.Visible = False
lblresult.Text = ""
lblresult.Text = "You appear to already be registered
in the system. If you are having trouble logging in, please contact
your GIO."
End If
lnkAdd.Enabled = True

pnlform.Visible = False
pnlresult.Visible = True

user = Nothing
map = Nothing
roles = Nothing
End Sub
#End Region

#Region " Data Related Procedures "

'********************************************************************************************************
'Name: FillForm
'Parameters: None
'Returns: Nothing
'Purpose: Attempts to query the active directory for required
data. Not successful after CAC Integration.

'********************************************************************************************************
Private Sub FillForm()
Dim dbuser As New Orgz.User
Dim name As String
name = dbuser.getuseridbyusername()
dbuser = dbuser.getuserbyusername(name)
Dim str As New System.Text.StringBuilder

If Not (IsNothing(dbuser)) Then
pnlresult.Visible = True
pnlPreFill.Visible = False
pnlform.Visible = False
lblresult.Text = ""
lblresult.Text = "You have registered but haven't been
activated yet. Please be patient and you will be activated soon."
Else
str.Append("LDAP://")
str.Append(ConfigurationManager.AppSettings("addomain"))
Dim enTry As DirectoryEntry = New
DirectoryEntry(str.ToString)
Dim mySearcher As DirectorySearcher = New
DirectorySearcher(enTry)
str.Remove(0, str.Length)
str.Append("(SAMAccountName=")
str.Append(name)
str.Append(")")
mySearcher.Filter = str.ToString
Dim bol As ResultPropertyCollection
Try
Dim result As SearchResult = mySearcher.FindOne
bol = result.Properties
Catch
bol = Nothing
End Try
mySearcher.Dispose()
enTry.Dispose()
mySearcher = Nothing
enTry = Nothing

…….bunch of unrelated code removed…….

End If
str = Nothing
End Sub
#End Region

#Region " Auxillary Procedures "

'********************************************************************************************************
'Name: sendmail
'Parameters: None
'Returns: Nothing
'Purpose: Sends mail to the GIO upon new user addition.

'********************************************************************************************************
Private Sub sendmail()
Dim msgmail As New Net.Mail.MailMessage
Dim m As New Net.Mail.SmtpClient
Dim FromAddress As New
Net.Mail.MailAddress(ConfigurationManager.AppSettings("automatedemailfrom"))
Dim str As New System.Text.StringBuilder
Dim user As New Orgz.User
For Each user In New
Orgz.Installation().GetInstallationAdmins(dpdinstallation.SelectedItem.Value)
msgmail.To.Add(user.txtemail)
Next

msgmail.To.Add(ConfigurationManager.AppSettings("registrationcontact"))
msgmail.From = FromAddress
str.Append("GeoBase Registration")
msgmail.Subject = str.ToString
msgmail.IsBodyHtml = False
str.Remove(0, str.Length)
str.Append(String.Format("blah blah blah",
user.txtfirstname, user.txtlastname,
Orgz.User.GetHyperLinkBase(Request.ServerVariables("CERT_SUBJECT"))))
msgmail.Body = str.ToString

m.Host = ConfigurationManager.AppSettings("smtpserver")
m.Port = 25

Try
m.Send(msgmail)
Catch ex As Exception
'Throw New Exception("Your email could not be sent" &
ex.Message & ex.StackTrace)
End Try

FromAddress = Nothing
msgmail = Nothing
user = Nothing
m = Nothing
End Sub
#End Region

Protected Sub dpdMajCom_SelectedIndexChanged(ByVal sender As
Object, ByVal e As System.EventArgs) Handles
dpdMajCom.SelectedIndexChanged
Dim installation As New Orgz.Installation
dpdinstallation.DataTextField = "installationname"
dpdinstallation.DataValueField = "installationid"
dpdinstallation.DataSource =
installation.getInstallationsByMajcom(dpdMajCom.SelectedItem.Value)
dpdinstallation.DataBind()

installation = Nothing
End Sub
End Class

End Namespace



Any help is appreciated.
 
Am 29.09.2010 06:07, schrieb Dan Lewis:
Apologies up front if this is a simple thing, but I'm slowly learning
vb .net with a background in vbscript (much simpler!). I have a web
app that I'm trying to modify. The .aspx.vb file in question allows a
new user (orgzuser) to register and the user object is defined with
the code shown below. I'm trying to modify the code so that the users
are created (added to the associated database) with two roles
automatically (groupid of 1 and 4). Sounds simple, but I can't get it
to work because I'm not understanding the data types. From reading
the source files, I thought the datatype was integer (it is in the
database), but because the user object is a defined item (sorry if the
terminology is not correct), it appears to be a "special" datatype (in
vbscript, everything is basically text).

A lot of code. The only thing I see is this:
Dim roles As New System.Collections.Generic.List(Of
Orgz.Role)
'add ***
roles.add("1")
roles.add("4")
'end add ***

Variable 'roles' references a list of Orgz.Role objects. This type isn't
defined in the code you've posted. The code is trying to add Strings, but
only objects of type Orgz.Role can be added. Something like

roles.add(New Orgz.Role())

Maybe you have to pass parameters to the object's constructor.
 
Back
Top