get username using asp

Discussion in 'ASP General' started by James, Aug 6, 2009.

  1. James

    James Guest

    I have the following script & I need to get the username (with no
    domain info) & feed the username into c:\documents and settings
    \username\my documents". So, for instance, if the username is JSmith,
    then I'll have
    c:\documents and settings\JSmith\my documents below. Thanks

    ==================================================================================
    <HTML>

    <HEAD>
    <TITLE>This is only a test</TITLE>
    </HEAD>
    <BODY topmargin="0" leftmargin="0">
    <div align="center">
    <img border="0" src="picture.gif">

    <OBJECT width="994"
    CLASSID="CLSID:AAB0606-D808-479A-9398-34879AAA"
    ID="application1"
    CODEBASE="http://webserver//SupportWebSite/test.CAB#Version=5"
    VIEWASTEXT>
    <PARAM NAME="URL" VALUE="http://webserver//SupportWebSite" >
    <PARAM NAME="PATH" VALUE="c:\documents and settings\\my documents"
    >

    </OBJECT>
    </div>


    <TABLE align="center">
    <tr align="center" valign="middle">
    <td width="100%" valign="top"><br>
    <p align="center"><font face="Verdana, Arial, Helvetica, sans-
    serif" size="1">This is only a test.<br>
    </font><span class="bodytextblk"><br>
    </p>
    </td>
    </tr>
    </TABLE>

    </BODY>

    </HTML
    ===================================================================================
    James, Aug 6, 2009
    #1
    1. Advertising

  2. Gazing into my crystal ball I observed =?Utf-8?B?SmFtZXM=?=
    <> writing in
    news::

    > I have the following script & I need to get the username (with no
    > domain info) & feed the username into c:\documents and settings
    > \username\my documents". So, for instance, if the username is JSmith,
    > then I'll have
    > c:\documents and settings\JSmith\my documents below. Thanks
    >


    I'm sorry, but I have to say something here about your markup. Yes,
    this is a client side issue, but you should know that writing to
    standards will help you in the long run. Using semantic markup, without
    presentation is a lot simpler and easier to debug down the line.

    At very bottom of this post there is an answer to your original
    question. Read on.


    >=======================================================================

    =
    >========== <HTML>
    >
    ><HEAD>
    > <TITLE>This is only a test</TITLE>
    ></HEAD>
    ><BODY topmargin="0" leftmargin="0">

    The topmargin and bottom margin attributes of the TABLE element are
    deprecated. Use CSS.

    ><div align="center">

    The align attribute for the DIV element is deprecated. Use CSS.

    ><img border="0" src="picture.gif">

    The alt attribute of the IMG element is required.

    >


    <snip>

    >
    >
    ><TABLE align="center">
    > <tr align="center" valign="middle">
    > <td width="100%" valign="top"><br>
    > <p align="center"><font face="Verdana, Arial, Helvetica, sans-
    > serif" size="1">This is only a test.<br>
    > </font><span class="bodytextblk"><br>
    > </p>
    > </td>
    > </tr>
    ></TABLE>

    This bit is ridiculous! and so 90's! This is an abuse of tables.
    Tables are for marking up tabular data. A plain paragraph would be more
    suited, and if you wanted to make it center aligned, you could do this:

    <style type="text/css">
    body {margin:0; font-family: verdana, arial, helvetica, sans-serif;
    font-size:70% /*way to small*/; text-align:center;}
    </style>
    </head>
    <body>
    <p>What you want to say.</p>
    </body>

    Isn't that a lot easier? As promised:
    [http://www.4guysfromrolla.com/webtech/092298-3.shtml]
    Also see:
    [http://cavalcade-of-coding.info/fonttext.php] for why verdana is not a
    good font for the www.

    --
    Adrienne Boswell at Home
    Arbpen Web Site Design Services
    http://www.cavalcade-of-coding.info
    Please respond to the group so others can share
    Adrienne Boswell, Aug 6, 2009
    #2
    1. Advertising

  3. James

    James Guest

    unfortunately, the <%=Request.ServerVariables("LOGON_USER")%> did not work. I
    do not want to make the user login into the website to pull the "logon_user".
    This is a big hassle. I want to enable anonymous access. The user logins in
    into his/her workstation using his/her userid. Is there anyway thru asp or
    other language to pull this info into a webpage? That is, the %username% env
    variable is the one that I want to feed into the website. Thanks


    "Adrienne Boswell" wrote:

    > Gazing into my crystal ball I observed =?Utf-8?B?SmFtZXM=?=
    > <> writing in
    > news::
    >
    > > I have the following script & I need to get the username (with no
    > > domain info) & feed the username into c:\documents and settings
    > > \username\my documents". So, for instance, if the username is JSmith,
    > > then I'll have
    > > c:\documents and settings\JSmith\my documents below. Thanks
    > >

    >
    > I'm sorry, but I have to say something here about your markup. Yes,
    > this is a client side issue, but you should know that writing to
    > standards will help you in the long run. Using semantic markup, without
    > presentation is a lot simpler and easier to debug down the line.
    >
    > At very bottom of this post there is an answer to your original
    > question. Read on.
    >
    >
    > >=======================================================================

    > =
    > >========== <HTML>
    > >
    > ><HEAD>
    > > <TITLE>This is only a test</TITLE>
    > ></HEAD>
    > ><BODY topmargin="0" leftmargin="0">

    > The topmargin and bottom margin attributes of the TABLE element are
    > deprecated. Use CSS.
    >
    > ><div align="center">

    > The align attribute for the DIV element is deprecated. Use CSS.
    >
    > ><img border="0" src="picture.gif">

    > The alt attribute of the IMG element is required.
    >
    > >

    >
    > <snip>
    >
    > >
    > >
    > ><TABLE align="center">
    > > <tr align="center" valign="middle">
    > > <td width="100%" valign="top"><br>
    > > <p align="center"><font face="Verdana, Arial, Helvetica, sans-
    > > serif" size="1">This is only a test.<br>
    > > </font><span class="bodytextblk"><br>
    > > </p>
    > > </td>
    > > </tr>
    > ></TABLE>

    > This bit is ridiculous! and so 90's! This is an abuse of tables.
    > Tables are for marking up tabular data. A plain paragraph would be more
    > suited, and if you wanted to make it center aligned, you could do this:
    >
    > <style type="text/css">
    > body {margin:0; font-family: verdana, arial, helvetica, sans-serif;
    > font-size:70% /*way to small*/; text-align:center;}
    > </style>
    > </head>
    > <body>
    > <p>What you want to say.</p>
    > </body>
    >
    > Isn't that a lot easier? As promised:
    > [http://www.4guysfromrolla.com/webtech/092298-3.shtml]
    > Also see:
    > [http://cavalcade-of-coding.info/fonttext.php] for why verdana is not a
    > good font for the www.
    >
    > --
    > Adrienne Boswell at Home
    > Arbpen Web Site Design Services
    > http://www.cavalcade-of-coding.info
    > Please respond to the group so others can share
    >
    >
    James, Aug 6, 2009
    #3
  4. James

    Bob Barrows Guest

    Err ... "anonymous" means "anonymous".
    I'm assuming you are doing this for an intranet rather than the
    internet, and that the client machine is in the same domain as the web
    server (or in a trusted domain). If so, go into the website's properties
    in IIS Manager and
    1. Enable Integrate Authentication so the user's network credentials are
    used to authenticate the user
    and
    2. Disable Anonymous so the user's login name is put in the Request's
    ServerVariables collection.

    If this is an internet application, then you are SOL.

    Further info
    1. You cannot access the %username% evironment variable on the client's
    machine from server-side script (or any other information on the
    client's machine that is not provided as part of the http request, for
    that matter).
    2. Default browser security security settings will also prevent
    client-side script from accessing this sort of information as well.
    Hacker exploits have made browser creators very strict about what
    client-side script is allowed to see on a user's machine. I'm not even
    sure if this would be possible if the user was convinced to lower his
    browser security settings for your site.


    James wrote:
    > unfortunately, the <%=Request.ServerVariables("LOGON_USER")%> did not
    > work. I do not want to make the user login into the website to pull
    > the "logon_user". This is a big hassle. I want to enable anonymous
    > access. The user logins in into his/her workstation using his/her
    > userid. Is there anyway thru asp or other language to pull this info
    > into a webpage? That is, the %username% env variable is the one that
    > I want to feed into the website. Thanks
    >
    >
    > "Adrienne Boswell" wrote:
    >
    >> Isn't that a lot easier? As promised:
    >> [http://www.4guysfromrolla.com/webtech/092298-3.shtml]



    --
    HTH,
    Bob Barrows
    Bob Barrows, Aug 6, 2009
    #4
  5. James

    Dooza Guest

    Bob Barrows wrote:
    > Err ... "anonymous" means "anonymous".
    > I'm assuming you are doing this for an intranet rather than the
    > internet, and that the client machine is in the same domain as the web
    > server (or in a trusted domain). If so, go into the website's properties
    > in IIS Manager and
    > 1. Enable Integrate Authentication so the user's network credentials are
    > used to authenticate the user
    > and
    > 2. Disable Anonymous so the user's login name is put in the Request's
    > ServerVariables collection.


    I use this method for our intranet. If your using Firefox you need to
    change a few hidden settings to allow that server to authenticate you.

    Type about:config in the address bar
    Find the following and add the address of your intranet server to them:

    network.automatic-ntlm-auth.trusted-uris
    network.negotiate-auth.delegation-uris
    network.negotiate-auth.trusted-uris

    I haven't tried any other browser.

    Dooza
    Dooza, Aug 7, 2009
    #5
  6. James

    Dooza Guest

    James wrote:
    > I've used the following command to get the currently logged on user:
    >
    > <% WhoAmI = Request.ServerVariables("LOGON_USER") %>
    >
    > This returns a value of "Domain\username"
    >
    > Is there a way to truncate that value by removing "domain\" from it? All I
    > need is username without the domain prefix. Thanks


    <% WhoAmI = REPLACE(Request.ServerVariables("LOGON_USER"),"domain\","") %>

    Dooza
    Dooza, Aug 13, 2009
    #6
  7. James

    Evertjan. Guest

    Dooza wrote on 13 aug 2009 in microsoft.public.inetserver.asp.general:

    > James wrote:
    >> I've used the following command to get the currently logged on user:
    >>
    >> <% WhoAmI = Request.ServerVariables("LOGON_USER") %>
    >>
    >> This returns a value of "Domain\username"
    >>
    >> Is there a way to truncate that value by removing "domain\" from it?
    >> All I need is username without the domain prefix. Thanks

    >
    > <% WhoAmI =
    > REPLACE(Request.ServerVariables("LOGON_USER"),"domain\","") %>


    even simpler:

    <%
    WhoAmI = MID(Request.ServerVariables("LOGON_USER"),8)
    %>

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

    but if the length and content of the letters in "domain\" is unknown:

    <%
    WhoAmI = Request.ServerVariables("LOGON_USER")
    WhoAmI = MID(WhoAmI,INSTR(WhoAmI,"\")+1)
    %>


    --
    Evertjan.
    The Netherlands.
    (Please change the x'es to dots in my emailaddress)
    Evertjan., Aug 13, 2009
    #7
  8. James

    Dooza Guest

    Evertjan. wrote:
    > Dooza wrote on 13 aug 2009 in microsoft.public.inetserver.asp.general:
    >
    >> James wrote:
    >>> I've used the following command to get the currently logged on user:
    >>>
    >>> <% WhoAmI = Request.ServerVariables("LOGON_USER") %>
    >>>
    >>> This returns a value of "Domain\username"
    >>>
    >>> Is there a way to truncate that value by removing "domain\" from it?
    >>> All I need is username without the domain prefix. Thanks

    >> <% WhoAmI =
    >> REPLACE(Request.ServerVariables("LOGON_USER"),"domain\","") %>

    >
    > even simpler:
    >
    > <%
    > WhoAmI = MID(Request.ServerVariables("LOGON_USER"),8)
    > %>
    >
    > ============================
    >
    > but if the length and content of the letters in "domain\" is unknown:
    >
    > <%
    > WhoAmI = Request.ServerVariables("LOGON_USER")
    > WhoAmI = MID(WhoAmI,INSTR(WhoAmI,"\")+1)
    > %>


    Very nice, I will keep that one for later use!

    Dooza
    Dooza, Aug 17, 2009
    #8
    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. Replies:
    5
    Views:
    4,954
  2. Luqman
    Replies:
    1
    Views:
    455
    Cowboy \(Gregory A. Beamer\)
    Nov 24, 2006
  3. James

    get username using asp.net

    James, Aug 5, 2009, in forum: ASP .Net
    Replies:
    2
    Views:
    596
    Gregory A. Beamer
    Aug 5, 2009
  4. Shailesh Patel
    Replies:
    0
    Views:
    436
    Shailesh Patel
    Nov 8, 2006
  5. Primoz Bradac

    How to get username on IIS run intranet (ASP)

    Primoz Bradac, Aug 12, 2008, in forum: ASP General
    Replies:
    5
    Views:
    323
    Bob Barrows [MVP]
    Aug 12, 2008
Loading...

Share This Page