Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / September 2007

Tip: Looking for answers? Try searching our database.

need help with understanding this little bit of code

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Daniel - 06 Sep 2007 22:11 GMT
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)

Signature

ASP, SQL2005, DW8 VBScript

Mark Rae [MVP] - 06 Sep 2007 22:22 GMT
> According to some of the programmers that use to work here and on this
> code, it was done in VB and .NET
[quoted text clipped - 3 lines]
>
> 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)...

Signature

Mark Rae
ASP.NET MVP
http://www.markrae.net

Daniel - 06 Sep 2007 22:56 GMT
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?

Signature

ASP, SQL2005, DW8 VBScript

>
>> According to some of the programmers that use to work here and on this
[quoted text clipped - 10 lines]
> and then returning the second element in that array (arrays are zero-based
> by default)...
Milosz Skalecki [MCAD] - 06 Sep 2007 23:30 GMT
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
Signature

Milosz

> According to some of the programmers that use to work here and on this code,
> it was done in VB and .NET
[quoted text clipped - 3 lines]
>
> UID = User.Identity.Name.Split("\"c)(1)
Daniel - 10 Sep 2007 19:36 GMT
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
Signature

ASP, SQL2005, DW8 VBScript

> Daniel,
>
[quoted text clipped - 31 lines]
>>
>> UID = User.Identity.Name.Split("\"c)(1)
Milosz Skalecki [MCAD] - 12 Sep 2007 23:04 GMT
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
Signature

Milosz

> With that said.. would there be any reason why the code would be ignoring
> users with numerical values in there userid?
[quoted text clipped - 43 lines]
> >>
> >> UID = User.Identity.Name.Split("\"c)(1)
Daniel - 12 Sep 2007 23:26 GMT
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.

Signature

ASP, SQL2005, DW8 VBScript

> Hi Daniel,
>
[quoted text clipped - 58 lines]
>> >>
>> >> UID = User.Identity.Name.Split("\"c)(1)
Milosz Skalecki [MCAD] - 13 Sep 2007 18:28 GMT
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
Signature

Milosz

> Here is more of the code: ( this is bits of the code.... )
> Private Sub GetPrefixInfo()
[quoted text clipped - 189 lines]
> >> >>
> >> >> UID = User.Identity.Name.Split("\"c)(1)
Daniel - 13 Sep 2007 20:16 GMT
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

Signature

ASP, SQL2005, DW8 VBScript

> Howdy,
>
[quoted text clipped - 212 lines]
>> >> >>
>> >> >> UID = User.Identity.Name.Split("\"c)(1)

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.