0

I Googled about this, but none of solutions solved this situation.

My web.config:

<configuration>
    <system.web>
        <customErrors mode="Off"/>
        <compilation debug="true">
            </compilation>
      <authentication mode="Windows" />

    </system.web>
</configuration>

My aspx page:

<script runat="server">
    void Page_Load(object sender, EventArgs e)
    {
        string opl = System.Security.Principal.WindowsIdentity.GetCurrent().Name.ToString();
        Response.Write("Name:" + opl);
    }
</script>

I'm getting an empty string, any ideas?I tried Request.ServerVariables but get an empty string for user also.

Brandon
  • 645
  • 5
  • 13
luckasx
  • 359
  • 1
  • 6
  • 20
  • 1
    possible duplicate of [how to get currently loggedin windows account from an asp.net page](http://stackoverflow.com/questions/16184685/how-to-get-currently-loggedin-windows-account-from-an-asp-net-page) – ale May 07 '14 at 17:36
  • I got it disabling anonymous access. =D. In the web.config I add this – luckasx May 07 '14 at 17:50

3 Answers3

2

If you want to get the name of the logged user you can use

var user = User.Identity.Name

or

var user = User.Identity.UserName

kevinkrs
  • 108
  • 4
1

Try this instead:

var username = User.Identity.Name
Nathan A
  • 11,059
  • 4
  • 47
  • 63
0

What you want to do is consult the HttpContext:

http://msdn.microsoft.com/en-us/library/system.web.httpcontext.user.aspx

It will contain all of the information about the currently logged in user.

Mike Cheel
  • 12,626
  • 10
  • 72
  • 101