need help with understanding this little bit of code

D

Daniel

According to some of the programmers that use to work here and on this code,
it was done in VB and .NET

Can anyone explain what the letter c and the number 1 in this line of code
stand for?



UID = User.Identity.Name.Split("\"c)(1)
 
M

Mark Rae [MVP]

According to some of the programmers that use to work here and on this
code, it was done in VB and .NET

Can anyone explain what the letter c and the number 1 in this line of code
stand for?

UID = User.Identity.Name.Split("\"c)(1)

User.Identity.Name will ordinarily return DOMAIN\UserID

The above code is splitting that into an array based on the "\" character,
and then returning the second element in that array (arrays are zero-based
by default)...
 
D

Daniel

so if i understand your reply...

If a user logs in as mydomain\jsmith

Splits it into

mydomain
jsmith

So based on that code.. what SHOULD happen to a user that has a numerical
value in there userid?

jsmith2

Reason im asking, is it seems that if a user has a numerical value in there
ID it ignores that number and defaults to anyone else with a similar ID

So the following 2 people exist here

jsmith
jsmith2

It seems to be ignoring the 2 and defaults to jsmith
So is the letter c in the code looking at just strickly characters? if so
what can we use to take characters and numbers?
 
G

Guest

Daniel,

"a"c in vb.net distinguishes the char type from the string type. Char type
represents any single unicode character (a letter, a digit, + - \ / space,
return, $ % etc.) whilst string is a sequence of many characters (simplifying
string is an array of Char-s).
"\"c represents backslash character. (1) is the second element (because this
is zero-index based array) in the array of strings returned from Split()
function. It shouldn't skip numeric characters. Try

dim result as String() = User.Identity.Name.Split(new Char() { "\"c } )

dim domain as string = result(0)
dim user as string = result(1)

if result.Length > 0 then
domain = result(0)
if result.Length > 1 Then
user = result(1)
end if
end if

HTH
 
D

Daniel

With that said.. would there be any reason why the code would be ignoring
users with numerical values in there userid?

Im just trying to figure out if the code is ignoring the number in the id
and defaulting to the first person that meets thefirst part of the name...

jdoe ( Joe Doe )
jdoe2 ( John Doe )

even though the user names are similar everything is unique

When jdoe logs in.... he gets access to jdoe2 data
 
G

Guest

Hi Daniel,

I think everything is ok with the code you posted. I suspect there's a dodgy
logic before/afterwards. Have you debugged the code so you can confirm
numeric character(s) are truncated. Could you please paste a bigger chunk of
code so we could have a look?

Regards
 
D

Daniel

Here is more of the code: ( this is bits of the code.... )
Private Sub GetPrefixInfo()

'Put user code to initialize the page here

Dim occAssocInfo As cAssocInfo = New cAssocInfo()

Dim odsPrefixInfo As dsPrefixData = New dsPrefixData()

Dim selAlpha As Char

'Get Store ID, Employee and Contractor Prefixes

odsPrefixInfo = occAssocInfo.GetPrefix()

Session.Clear()

Session("iEmpPrefix") = odsPrefixInfo.usp_GetPrefix(0).emp_prefix

Session("iContrPrefix") = odsPrefixInfo.usp_GetPrefix(0).contr_prefix

Session("sBarCodeDir") = odsPrefixInfo.usp_GetPrefix(0).seq_descr

Session("PageID") = "Main"

Session("iStoreID") = iStoreID

Session("UIDType") = UIDType

--------------------------

Function getStoreNumberFromIP()

Dim sIPAddress As String

Dim iSplitID As Integer

sIPAddress = Request.ServerVariables("REMOTE_ADDR")

iSplitID = CInt(sIPAddress.Split("."c)(1))

'Identify all valid store id

If iSplitID < 2 Or iSplitID > 99 Then

iSplitID = 999

End If

Return iSplitID

End Function

----------------------------------------

'Find the user on the email list

Try

GRSearch.Filter = "(&(objectCategory=user)(mail=" & UID & "*))"

oResults = GRSearch.FindAll()

'Determine if the user is in the group of valid users

For Each oResult In oResults

For iMemCount = 0 To
oResult.GetDirectoryEntry().Properties("memberOf").Count - 1

strMember = oResult.GetDirectoryEntry().Properties("memberOf")(iMemCount)

iEqlIdx = strMember.IndexOf("=", 1)

iComIdx = strMember.IndexOf(",", 1)

strGroupName = strMember.Substring(iEqlIdx + 1, (iComIdx - iEqlIdx) - 1)

'Check if the Group is a valid user or not

If strGroupName = GRAdminGroup Then

UIDType = "Admin"

bValid = True

End If

If strGroupName = GRUserGroup Then

UIDType = "User"

bValid = True

End If

'Check if there is a Store Group for the user

If Len(strGroupName) >= 7 Then

If UCase(strGroupName.Substring(0, 5)) = "STORE" Then

'Extract StoreID

If IsNumeric(strGroupName.Substring(5, 2)) Then

iStoreID = CInt(strGroupName.Substring(5, 2))

End If

End If

End If

Next

Next

Catch e1 As Exception

Return False

End Try

================================================

This is not in order, but the bits the seem to have to do with the
validating the user...



thanks.
 
G

Guest

Howdy,

what about this line?:

GRSearch.Filter = "(&(objectCategory=user)(mail=" & UID & "*))"

Seems wjen the lgon is john, it will apply the logic for any john* (i.e.
john2) My advice would be to debug the original line
UID = User.Identity.Name.Split("\"c)(1)
to see value of the UID just after the statement has been executed. But my
gut feeling is the line i have just pointed out is the source of your issue.

HTH
 
D

Daniel

Thank you for the suggestion, i will continue to pester the old programmers
that are still here to see if they know where the original code is so we can
test on another server...

thanks
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,011
Latest member
AjaUqq1950

Latest Threads

Top