Capturing Windows Login with ASP

Discussion in 'ASP General' started by dave, Sep 13, 2004.

  1. dave

    dave Guest

    Hi I have succesfully captured the users login detail, but I now
    have a new problem I have assigned the login to a Session Variable, however
    when I come to use the string stored in the variable it excludes the \ which
    seperates the domain from the user name, it should be :DOMAIN\USERNAME , but
    I am getting DOMAINUSERNAME which really is a pain. Anybody
    know why this is happening and how I can overcome it ?

    Thanks
     
    dave, Sep 13, 2004
    #1
    1. Advertising

  2. dave

    Harag Guest

    On Mon, 13 Sep 2004 08:17:57 +0000 (UTC), "dave"
    <> wrote:

    >Hi I have succesfully captured the users login detail, but I now
    >have a new problem I have assigned the login to a Session Variable, however
    >when I come to use the string stored in the variable it excludes the \ which
    >seperates the domain from the user name, it should be :DOMAIN\USERNAME , but
    >I am getting DOMAINUSERNAME which really is a pain. Anybody
    >know why this is happening and how I can overcome it ?
    >
    >Thanks
    >


    are you using vbscript or jscript?

    I guess jscript. "\" is the esc chr for jscript, you might need to
    replace it with 2 "\\"

    hth

    al.
     
    Harag, Sep 13, 2004
    #2
    1. Advertising

  3. dave

    dave Guest

    "Harag" <> wrote in message
    news:...
    > On Mon, 13 Sep 2004 08:17:57 +0000 (UTC), "dave"
    > <> wrote:
    >
    >>Hi I have succesfully captured the users login detail, but I now
    >>have a new problem I have assigned the login to a Session Variable,
    >>however
    >>when I come to use the string stored in the variable it excludes the \
    >>which
    >>seperates the domain from the user name, it should be :DOMAIN\USERNAME ,
    >>but
    >>I am getting DOMAINUSERNAME which really is a pain. Anybody
    >>know why this is happening and how I can overcome it ?
    >>
    >>Thanks
    >>

    >
    > are you using vbscript or jscript?
    >
    > I guess jscript. "\" is the esc chr for jscript, you might need to
    > replace it with 2 "\\"
    >
    > hth
    >
    > al.
    >


    vbscript
     
    dave, Sep 13, 2004
    #3
  4. dave

    dave Guest

    "Harag" <> wrote in message
    news:...
    > On Mon, 13 Sep 2004 08:17:57 +0000 (UTC), "dave"
    > <> wrote:
    >
    >>Hi I have succesfully captured the users login detail, but I now
    >>have a new problem I have assigned the login to a Session Variable,
    >>however
    >>when I come to use the string stored in the variable it excludes the \
    >>which
    >>seperates the domain from the user name, it should be :DOMAIN\USERNAME ,
    >>but
    >>I am getting DOMAINUSERNAME which really is a pain. Anybody
    >>know why this is happening and how I can overcome it ?
    >>
    >>Thanks
    >>

    >
    > are you using vbscript or jscript?
    >
    > I guess jscript. "\" is the esc chr for jscript, you might need to
    > replace it with 2 "\\"
    >
    > hth
    >
    > al.
    >


    I have just realised that my problem lies elsewhere ! I am holding the user
    login in a table which is passed to a new webpage via the URL and I am
    reading the the variable from the query string ! This is where the character
    is getting lost I believe, but I still do not know how to cure, so any more
    help would be gratefully received.

    Thanks

    Dave
     
    dave, Sep 13, 2004
    #4
  5. dave

    Harag Guest

    On Mon, 13 Sep 2004 09:07:07 +0000 (UTC), "dave"
    <> wrote:

    >"Harag" <> wrote in message
    >news:...
    >> On Mon, 13 Sep 2004 08:17:57 +0000 (UTC), "dave"
    >> <> wrote:
    >>
    >>>Hi I have succesfully captured the users login detail, but I now
    >>>have a new problem I have assigned the login to a Session Variable,
    >>>however
    >>>when I come to use the string stored in the variable it excludes the \
    >>>which
    >>>seperates the domain from the user name, it should be :DOMAIN\USERNAME ,
    >>>but
    >>>I am getting DOMAINUSERNAME which really is a pain. Anybody
    >>>know why this is happening and how I can overcome it ?
    >>>
    >>>Thanks
    >>>

    >>
    >> are you using vbscript or jscript?
    >>
    >> I guess jscript. "\" is the esc chr for jscript, you might need to
    >> replace it with 2 "\\"
    >>
    >> hth
    >>
    >> al.
    >>

    >
    >I have just realised that my problem lies elsewhere ! I am holding the user
    >login in a table which is passed to a new webpage via the URL and I am
    >reading the the variable from the query string ! This is where the character
    >is getting lost I believe, but I still do not know how to cure, so any more
    >help would be gratefully received.
    >
    >Thanks
    >
    >Dave
    >



    are you encoding the querystring?

    <a href="mypage.asp?sting=<%= Server.URLEncode("domain\user")
    %>">click me</a>
     
    Harag, Sep 13, 2004
    #5
  6. dave

    JP SIngh Guest

    Try this

    sFullUser = trim(Request.ServerVariables ("LOGON_USER"))
    sFullUser = replace(sFullUser,"/","\")
    iPos = InStr(sFullUser, "\")
    sDomain = Left(sFullUser, iPos - 1)
    strUserName = Mid(sFullUser, iPos + 1)


    make sure you have "Integrated Windows Auth" turned on your server



    "dave" <> wrote in message
    news:ci3l3l$g0q$...
    > Hi I have succesfully captured the users login detail, but I now
    > have a new problem I have assigned the login to a Session Variable,

    however
    > when I come to use the string stored in the variable it excludes the \

    which
    > seperates the domain from the user name, it should be :DOMAIN\USERNAME ,

    but
    > I am getting DOMAINUSERNAME which really is a pain. Anybody
    > know why this is happening and how I can overcome it ?
    >
    > Thanks
    >
    >
     
    JP SIngh, Sep 13, 2004
    #6
  7. dave

    Jeff Cochran Guest

    On Mon, 13 Sep 2004 09:07:07 +0000 (UTC), "dave"
    <> wrote:

    >"Harag" <> wrote in message
    >news:...
    >> On Mon, 13 Sep 2004 08:17:57 +0000 (UTC), "dave"
    >> <> wrote:
    >>
    >>>Hi I have succesfully captured the users login detail, but I now
    >>>have a new problem I have assigned the login to a Session Variable,
    >>>however
    >>>when I come to use the string stored in the variable it excludes the \
    >>>which
    >>>seperates the domain from the user name, it should be :DOMAIN\USERNAME ,
    >>>but
    >>>I am getting DOMAINUSERNAME which really is a pain. Anybody
    >>>know why this is happening and how I can overcome it ?
    >>>
    >>>Thanks
    >>>

    >>
    >> are you using vbscript or jscript?
    >>
    >> I guess jscript. "\" is the esc chr for jscript, you might need to
    >> replace it with 2 "\\"
    >>
    >> hth
    >>
    >> al.
    >>

    >
    >I have just realised that my problem lies elsewhere ! I am holding the user
    >login in a table which is passed to a new webpage via the URL and I am
    >reading the the variable from the query string ! This is where the character
    >is getting lost I believe, but I still do not know how to cure, so any more
    >help would be gratefully received.


    Either encode the query string, using HTMLEncode or URLEncode, or what
    I do is split the string to domain and user and store them separately.

    Jeff
     
    Jeff Cochran, Sep 13, 2004
    #7
  8. dave

    dave Guest

    "Jeff Cochran" <> wrote in message
    news:...
    > On Mon, 13 Sep 2004 09:07:07 +0000 (UTC), "dave"
    > <> wrote:
    >
    >>"Harag" <> wrote in message
    >>news:...
    >>> On Mon, 13 Sep 2004 08:17:57 +0000 (UTC), "dave"
    >>> <> wrote:
    >>>
    >>>>Hi I have succesfully captured the users login detail, but I now
    >>>>have a new problem I have assigned the login to a Session Variable,
    >>>>however
    >>>>when I come to use the string stored in the variable it excludes the \
    >>>>which
    >>>>seperates the domain from the user name, it should be :DOMAIN\USERNAME ,
    >>>>but
    >>>>I am getting DOMAINUSERNAME which really is a pain. Anybody
    >>>>know why this is happening and how I can overcome it ?
    >>>>
    >>>>Thanks
    >>>>
    >>>
    >>> are you using vbscript or jscript?
    >>>
    >>> I guess jscript. "\" is the esc chr for jscript, you might need to
    >>> replace it with 2 "\\"
    >>>
    >>> hth
    >>>
    >>> al.
    >>>

    >>
    >>I have just realised that my problem lies elsewhere ! I am holding the
    >>user
    >>login in a table which is passed to a new webpage via the URL and I am
    >>reading the the variable from the query string ! This is where the
    >>character
    >>is getting lost I believe, but I still do not know how to cure, so any
    >>more
    >>help would be gratefully received.

    >
    > Either encode the query string, using HTMLEncode or URLEncode, or what
    > I do is split the string to domain and user and store them separately.
    >
    > Jeff


    Excuse my ignorance, but how do I split the string ? as I feel this would be
    the best way forward.

    Dave
     
    dave, Sep 13, 2004
    #8
  9. dave

    Harag Guest

    On Mon, 13 Sep 2004 16:05:32 +0000 (UTC), "dave"
    <> wrote:

    [snipped a load of lines]

    >> Jeff

    >
    >Excuse my ignorance, but how do I split the string ? as I feel this would be
    >the best way forward.
    >
    >Dave


    Extracted from the MS scripting documents v5.6

    HTH
    Al.

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


    Returns a zero-based, one-dimensional array containing a specified
    number of substrings.

    Split(expression[, delimiter[, count[, compare]]])
    Arguments
    expression
    Required. String expression containing substrings and delimiters. If
    expression is a zero-length string, Split returns an empty array, that
    is, an array with no elements and no data.
    delimiter
    Optional. String character used to identify substring limits. If
    omitted, the space character (" ") is assumed to be the delimiter. If
    delimiter is a zero-length string, a single-element array containing
    the entire expression string is returned.
    count
    Optional. Number of substrings to be returned; -1 indicates that all
    substrings are returned.
    compare
    Optional. Numeric value indicating the kind of comparison to use when
    evaluating substrings. See Settings section for values.
    Settings
    The compare argument can have the following values:

    Constant Value Description
    vbBinaryCompare 0 Perform a binary comparison.
    vbTextCompare 1 Perform a textual comparison.

    Remarks
    The following example uses the Split function to return an array from
    a string. The function performs a textual comparison of the delimiter,
    and returns all of the substrings.

    Dim MyString, MyArray, Msg
    MyString = "VBScriptXisXfun!"
    MyArray = Split(MyString, "x", -1, 1)
    ' MyArray(0) contains "VBScript".
    ' MyArray(1) contains "is".
    ' MyArray(2) contains "fun!".
    Msg = MyArray(0) & " " & MyArray(1)
    Msg = Msg & " " & MyArray(2)
    MsgBox Msg

    >
     
    Harag, Sep 13, 2004
    #9
  10. dave

    Dave Guest

    Thanks guys, has sorted out my problems. Cant thank you all enough !

    Dave
    "JP SIngh" <> wrote in message
    news:%...
    > Try this
    >
    > sFullUser = trim(Request.ServerVariables ("LOGON_USER"))
    > sFullUser = replace(sFullUser,"/","\")
    > iPos = InStr(sFullUser, "\")
    > sDomain = Left(sFullUser, iPos - 1)
    > strUserName = Mid(sFullUser, iPos + 1)
    >
    >
    > make sure you have "Integrated Windows Auth" turned on your server
    >
    >
    >
    > "dave" <> wrote in message
    > news:ci3l3l$g0q$...
    > > Hi I have succesfully captured the users login detail, but I now
    > > have a new problem I have assigned the login to a Session Variable,

    > however
    > > when I come to use the string stored in the variable it excludes the \

    > which
    > > seperates the domain from the user name, it should be :DOMAIN\USERNAME ,

    > but
    > > I am getting DOMAINUSERNAME which really is a pain. Anybody
    > > know why this is happening and how I can overcome it ?
    > >
    > > Thanks
    > >
    > >

    >
    >
     
    Dave, Sep 14, 2004
    #10
  11. dave

    Jeff Cochran Guest

    >> Either encode the query string, using HTMLEncode or URLEncode, or what
    >> I do is split the string to domain and user and store them separately.


    >Excuse my ignorance, but how do I split the string ? as I feel this would be
    >the best way forward.


    I use:

    strLogonUser = Request.ServerVariables("LOGON_USER")
    tmpUserID = Split(strLogonUser,"\")
    strUserDomain = tmpUserID(0)
    strUserName = tmpUserID(1)

    Now you can use UserName, UserDomain or LogonUser, whichever is
    appropriate for your needs.

    Jeff
     
    Jeff Cochran, Sep 14, 2004
    #11
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Twitch
    Replies:
    2
    Views:
    588
    Twitch
    Nov 18, 2003
  2. Paul Ponzelli
    Replies:
    5
    Views:
    3,792
  3. Twitch
    Replies:
    0
    Views:
    116
    Twitch
    Nov 17, 2003
  4. Replies:
    4
    Views:
    119
  5. Brave
    Replies:
    1
    Views:
    101
    Bob Barrows [MVP]
    Oct 24, 2007
Loading...

Share This Page