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.

2

3 Answers 3

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

Sign up to request clarification or add additional context in comments.

Comments

1

Try this instead:

var username = User.Identity.Name

2 Comments

Context.User.Identity.Name.Tostring(), get the user name logged into the asp.net application not the windows account name.
using this I get empty
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.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.