Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. Web Development
  3. ASP.NET
  4. about getting current user Identity

about getting current user Identity

Scheduled Pinned Locked Moved ASP.NET
securityhelpcsharptutorialquestion
7 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Allah Kaa Bandaa
    wrote on last edited by
    #1

    hi all, I have created an aps.net application. In web.config file we have but we are not using authorization tag. also we have . We are also using the anonymousaccess and giving one local user in the fields of anonymous access. It is required for our application. Now my problem is that, i want the name of user who is accessing the application. for example, if a person accesses the application from a remote computer, then i need that the identity of that user is displayed. During current situation, when i use "User.Identity.Name", then on runtime, null is returned from this property. and when i use "System.Security.Principal.WindowsIdentity.GetCurrent().Name.ToString()", then on runtime, when i access the application from a remote pc,then the name of user given as anonymous access is display rather than the actual user. Can somebody help me how can i get the actual user name keeping the conditions mentioned in first paragraph as it is.

    A M 2 Replies Last reply
    0
    • A Allah Kaa Bandaa

      hi all, I have created an aps.net application. In web.config file we have but we are not using authorization tag. also we have . We are also using the anonymousaccess and giving one local user in the fields of anonymous access. It is required for our application. Now my problem is that, i want the name of user who is accessing the application. for example, if a person accesses the application from a remote computer, then i need that the identity of that user is displayed. During current situation, when i use "User.Identity.Name", then on runtime, null is returned from this property. and when i use "System.Security.Principal.WindowsIdentity.GetCurrent().Name.ToString()", then on runtime, when i access the application from a remote pc,then the name of user given as anonymous access is display rather than the actual user. Can somebody help me how can i get the actual user name keeping the conditions mentioned in first paragraph as it is.

      A Offline
      A Offline
      Anushu
      wrote on last edited by
      #2

      Hi, I think you can user the HttpServariables to solve your problem, for instance "System.Web.HttpContext.Current.Request.ServerVariables("REMOTE_HOST")" - this gives the IP of a remote client machine..there are some 40 (not sure really) or so ServerVariables and you can use them for obtaining the username

      A 1 Reply Last reply
      0
      • A Anushu

        Hi, I think you can user the HttpServariables to solve your problem, for instance "System.Web.HttpContext.Current.Request.ServerVariables("REMOTE_HOST")" - this gives the IP of a remote client machine..there are some 40 (not sure really) or so ServerVariables and you can use them for obtaining the username

        A Offline
        A Offline
        Anushu
        wrote on last edited by
        #3

        Hi, its me again.. Check this out might help you "string sLOGGEDINUSER = System.Web.HttpContext.Current.Request.ServerVariables.Get("LOGON_USER");"

        A 1 Reply Last reply
        0
        • A Anushu

          Hi, its me again.. Check this out might help you "string sLOGGEDINUSER = System.Web.HttpContext.Current.Request.ServerVariables.Get("LOGON_USER");"

          A Offline
          A Offline
          Allah Kaa Bandaa
          wrote on last edited by
          #4

          It returned null during run time.... its behaviour is same as that of Page.User.Identity Can you suggest any other... I will be waiting for your response..

          1 Reply Last reply
          0
          • A Allah Kaa Bandaa

            hi all, I have created an aps.net application. In web.config file we have but we are not using authorization tag. also we have . We are also using the anonymousaccess and giving one local user in the fields of anonymous access. It is required for our application. Now my problem is that, i want the name of user who is accessing the application. for example, if a person accesses the application from a remote computer, then i need that the identity of that user is displayed. During current situation, when i use "User.Identity.Name", then on runtime, null is returned from this property. and when i use "System.Security.Principal.WindowsIdentity.GetCurrent().Name.ToString()", then on runtime, when i access the application from a remote pc,then the name of user given as anonymous access is display rather than the actual user. Can somebody help me how can i get the actual user name keeping the conditions mentioned in first paragraph as it is.

            M Offline
            M Offline
            minhpc_bk
            wrote on last edited by
            #5

            Hi there, IMO, you cannot get that information when the Anonymous mode is selected at IIS. Basically, when a http request arrives at IIS, IIS will authenticate the caller and pass the security token to the ASP.NET. If the Anonymous access is selected, IIS creates an access account for the anonymous user which by default is IUSR_MACHINE. So if you try to get the Identity.Name in code, then what you will receive is empty. For more information, you can see Building Secure ASP.NET Applications[^]

            A 1 Reply Last reply
            0
            • M minhpc_bk

              Hi there, IMO, you cannot get that information when the Anonymous mode is selected at IIS. Basically, when a http request arrives at IIS, IIS will authenticate the caller and pass the security token to the ASP.NET. If the Anonymous access is selected, IIS creates an access account for the anonymous user which by default is IUSR_MACHINE. So if you try to get the Identity.Name in code, then what you will receive is empty. For more information, you can see Building Secure ASP.NET Applications[^]

              A Offline
              A Offline
              Allah Kaa Bandaa
              wrote on last edited by
              #6

              Hi, I know that above mention thing.....but I was asking that is there any way that we can access that identity which arrives to IIS. I mean, does IIS store some where the identity that comes to it from external hosts? If it so then how can we retrieve it? If it is not so, then it is obvious that we cannot get it....

              M 1 Reply Last reply
              0
              • A Allah Kaa Bandaa

                Hi, I know that above mention thing.....but I was asking that is there any way that we can access that identity which arrives to IIS. I mean, does IIS store some where the identity that comes to it from external hosts? If it so then how can we retrieve it? If it is not so, then it is obvious that we cannot get it....

                M Offline
                M Offline
                minhpc_bk
                wrote on last edited by
                #7

                The answer is sadly no. When the Anonymous access is selected, the browser does not prompt the unauthenticated user for a user name and password, then you have no chance of getting that information either at IIS or in ASP.NET code. For more information, you can read the IIS documentation.

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups