Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Visual Basic > VB.NET 1.0 > VB.NET 2002/2003 Basics
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
VB.NET 2002/2003 Basics For coders who are new to Visual Basic, working in .NET versions 2002 or 2003 (1.0 and 1.1).
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB.NET 2002/2003 Basics section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old September 29th, 2010, 10:19 AM
Registered User
 
Join Date: Sep 2010
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Question Error BC30311 after modifying source

Apologies up front if this is a simple thing, and also if this is the wrong forum for this question, but I'm slowly learning vb .net with a background in vbscript (much simpler!). Yes, I'm new to .net and all related things, but have experience with ASP pages and vb/vbscript. 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:


Code:
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):


Code:
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.Valu­e) 
                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.
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Without modifying source code if we compile again, will it generate IL again? JitenSharma C# 2 March 22nd, 2009 03:41 AM
error in source while using masterpages dotnetuser ASP.NET 2.0 Basics 4 June 28th, 2007 09:10 AM
Modifying the WEB.CONFIG custom error element? savoym VS.NET 2002/2003 3 January 21st, 2005 02:45 PM
Error in source code compiling angelika J2EE 2 December 29th, 2003 11:45 AM



All times are GMT -4. The time now is 04:18 AM.


Powered by vBulletin®
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.