System Username and Domain

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • 1qa2ws

    System Username and Domain

    Hi,

    I need to get the windows current logged username and domain. Is it any
    possibility?

    1qa2ws


  • DotNet Coder

    #2
    Re: System Username and Domain

    If you are using WinForms or ASP.NET with Windows authentication:

    WinForms:

    System.Security .Principal.Wind owsIdentity wi =
    System.Security .Principal.Wind owsIdentity.Get Current();

    ASP.NET:

    System.Security .Principal.Wind owsIdentity wi =
    (System.Securit y.Principal.Win dowsIdentity)Ht tpContext.Curre nt.User;


    HTH,
    ~d

    1qa2ws wrote:[color=blue]
    > Hi,
    >
    > I need to get the windows current logged username and domain. Is it any
    > possibility?
    >
    > 1qa2ws
    >
    >[/color]

    Comment

    • 1qa2ws

      #3
      Re: System Username and Domain

      How it differs from System.Environm ent.UserName and
      System.Environm ent.UserDomainN ame?

      1qa2sw

      "DotNet Coder" <d0tn3tc0d3r@ya hoo.dot.com> wrote in message
      news:u6dE1AfQFH A.1476@TK2MSFTN GP09.phx.gbl...[color=blue]
      > If you are using WinForms or ASP.NET with Windows authentication:
      >
      > WinForms:
      >
      > System.Security .Principal.Wind owsIdentity wi =
      > System.Security .Principal.Wind owsIdentity.Get Current();
      >
      > ASP.NET:
      >
      > System.Security .Principal.Wind owsIdentity wi =
      > (System.Securit y.Principal.Win dowsIdentity)Ht tpContext.Curre nt.User;
      >
      >
      > HTH,
      > ~d
      >
      > 1qa2ws wrote:[color=green]
      >> Hi,
      >>
      >> I need to get the windows current logged username and domain. Is it any
      >> possibility?
      >>
      >> 1qa2ws[/color][/color]


      Comment

      • DotNet Coder

        #4
        Re: System Username and Domain

        Well, because, in the case of using ASP.NET, System.Environm ent.UserName
        /System.Environm ent.UserDomainN ame will return the name of the currently
        logged on user on the server. Not the client using your web application.

        In winforms, I suppose you could use System.Environm ent with no problem.

        HTH,
        ~d

        1qa2ws wrote:[color=blue]
        > How it differs from System.Environm ent.UserName and
        > System.Environm ent.UserDomainN ame?
        >
        > 1qa2sw
        >
        > "DotNet Coder" <d0tn3tc0d3r@ya hoo.dot.com> wrote in message
        > news:u6dE1AfQFH A.1476@TK2MSFTN GP09.phx.gbl...
        >[color=green]
        >>If you are using WinForms or ASP.NET with Windows authentication:
        >>
        >>WinForms:
        >>
        >>System.Securi ty.Principal.Wi ndowsIdentity wi =
        >>System.Securi ty.Principal.Wi ndowsIdentity.G etCurrent();
        >>
        >>ASP.NET:
        >>
        >>System.Securi ty.Principal.Wi ndowsIdentity wi =
        >>(System.Secur ity.Principal.W indowsIdentity) HttpContext.Cur rent.User;
        >>
        >>
        >>HTH,
        >>~d
        >>
        >>1qa2ws wrote:
        >>[color=darkred]
        >>>Hi,
        >>>
        >>>I need to get the windows current logged username and domain. Is it any
        >>>possibilit y?
        >>>
        >>>1qa2ws[/color][/color]
        >
        >
        >[/color]

        Comment

        • Willy Denoyette [MVP]

          #5
          Re: System Username and Domain


          "DotNet Coder" <d0tn3tc0d3r@ya hoo.dot.com> wrote in message
          news:Ol3PgSfQFH A.1884@TK2MSFTN GP15.phx.gbl...[color=blue]
          > Well, because, in the case of using ASP.NET, System.Environm ent.UserName
          > /System.Environm ent.UserDomainN ame will return the name of the currently
          > logged on user on the server. Not the client using your web application.
          >
          > In winforms, I suppose you could use System.Environm ent with no problem.
          >[/color]

          IMO, OP wasn't asking about ASP.NET, anyway your answer is incorrect. An
          empty or a bogus value will be returned by calling
          System.Environm ent.UserName from within asp.net, the reason is that "aspnet"
          has no associated profile (and as such no Environment block) as it is not an
          interactive login. Even if asp.net run's with domain credentials or as an
          interactive login it's profile isn't loaded and the Environment shouldn't be
          trusted.
          Note that in general calling System.Environm ent is only a valid option when
          the caller is associated with a login that has it's profile loaded (an
          interactive login), in all other cases it shouldn't be used.

          Willy.




          Comment

          Working...