#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2008
    Posts
    144
    Rep Power
    12

    Domain User name into Text field


    I have the following logon page and would like to echo the currently logged on username into the txtUserName text box. I have setup everything apporpriately on the server, as I can echo the username in php, however I have no idea how to do so using ASP.

    Code:
    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Login.aspx.cs" Inherits="WaspTime._Default" Title="WaspTime Web Portal" %>
    
    <%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="AJaxToolKit" %>
    <%--  Disable page caching  --%>
    <%--  Add these lines below for every page you don't want to be cached on the disk  --%>
    <%--  http://www.velocityreviews.com/forums/t297932-nocache-vs-nostore.html   --%>
    <%
        Response.Cache.SetCacheability(HttpCacheability.ServerAndNoCache);
        Response.Cache.SetAllowResponseInBrowserHistory(false);
        Response.Cache.SetNoStore();
    %>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <link id="Link1" runat="server" rel="shortcut icon" href="Images/favicon.ico" type="image/x-icon" />
        <link id="Link2" runat="server" rel="icon" href="Images/favicon.ico" type="image/ico" />
        <title>WaspTime</title>
        <%--Scripts include --%>
    
        <script language="javascript" src="Help/eHlpDhtm.js" type="text/javascript">     </script>
    
        <%--Script wrapper--%>
    
        <script type="text/javascript" language="javascript">
            function PopupHelpTopic(strURL) {
                BSSCPopup(strURL, 600, 400);
            }
    
        </script>
    
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
            <asp:ScriptManager ID="ScriptManager1" runat="server">
            </asp:ScriptManager>
            <AJaxToolKit:NoBot ID="NoBot1" runat="server" CutoffMaximumInstances="5" CutoffWindowSeconds="5"
                ResponseMinimumDelaySeconds="1" OnGenerateChallengeAndResponse="NoBot1_GenerateChallengeAndResponse" />
            <center>
                <table style="border-style: solid; border-width: thin; font-family: Verdana; font-size: 12px;
                    font-weight: bold; font-style: normal; background-color: #d0d0d0; text-align: center; background-image:url(images/WaspTime_Web_Login.jpg);">
                    <tr>
                        <td style="width:493px; height:343px;" >
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <asp:Label ID="lblUserName" runat="server" Text="User Name:" CssClass="LoginText"></asp:Label>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <asp:TextBox ID="txtUserName" runat="server" Text="DOMAIN USER HERE" MaxLength="20" Width="150px"></asp:TextBox>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <asp:Label ID="Label1" runat="server" Text="Password:" CssClass="LoginText"></asp:Label>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <asp:TextBox ID="txtPassword" runat="server" TextMode="Password" MaxLength="20" Width="150px"></asp:TextBox>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <asp:Button ID="btnLogin" Text="Login" runat="server" OnClick="btnLogin_Click" />
                        </td>
                    </tr>
                </table>
                <asp:Label ID="lblError" runat="server"></asp:Label>
            </center>
        </div>
        </form>
    </body>
    </html>
    I am new to .ASP. In PHP I would just echo $_SERVER['REMOTE_USER']; or something similar into Text=" " of that particular text box but when I try what I believe to be the ASP equivalent of Text="<%=request.servervariables("LOGON_USER");%>" the page throws errors. Thank you for reading.
    Last edited by gmrstudios; June 12th, 2014 at 03:01 AM.
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2008
    Posts
    144
    Rep Power
    12
    I was able to get this resolved. Here is the solution I used:

    Code:
        string userName = System.Web.HttpContext.Current.User.Identity.Name;
        txtUserName.Text = userName.Replace(@"DOMAINNAME\","");
    This put the logged on username into the txtUserName field and striped out the domain name and the backslash.
  4. #3
  5. No Profile Picture
    Grumpier old Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jun 2003
    Posts
    14,549
    Rep Power
    4542
    Thank you for posting your solution
    ======
    Doug G
    ======
    I've never been able to appreciate the sublime arrogance of folks who feel they were put on earth just to save other folks from themselves .." - Donald Hamilton
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2008
    Posts
    144
    Rep Power
    12
    Originally Posted by zero201192
    Thank you for posting your solution bit invaled
    What issue are you having? Maybe something was missed?
  8. #5
  9. Lazy Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    16,382
    Rep Power
    9645
    Originally Posted by gmrstudios
    What issue are you having? Maybe something was missed?
    Spam. Feel free to forget it ever happened.

    Comments on this post

    • muscle_crowe agrees : Thanks for taking care of that!
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2014
    Posts
    44
    Rep Power
    4
    To get the current userid name of an asp.net aspx page use
    PHP Code:
    System.Security.Principal.WindowsIdentity.GetCurrent().Name 
    To get the actual person who's logged in use any of these:
    PHP Code:
          HttpContext.Current.User.Identity.Name
          Page
    .User (wraps HttpContext.Current.User.Identity.Name)
          
    Request.ServerVariables("logon_user"

IMN logo majestic logo threadwatch logo seochat tools logo