Retrieving Username
-
Hi I'm new to C# & .Net and the wonderful world of web services so forgive me if this is a simple and/or stupid question :doh: The WebService we are writing needs to determine which user is using it. We are using Digest Authentication (thus handled by Windows before it hits the service) so the user/password login prompt is already taken care of. But how do we determine the user from within the code after this. I tried using, System.Security.Principal.WindowsIdentity.GetCurrent().Name.ToString() but this just returned NT AUTHORITY\SYSTEM which is of no real use when I know I typed in TEST1 as the username. :confused: Any help would be gratefully received - Thanks in advance Brian
-
Hi I'm new to C# & .Net and the wonderful world of web services so forgive me if this is a simple and/or stupid question :doh: The WebService we are writing needs to determine which user is using it. We are using Digest Authentication (thus handled by Windows before it hits the service) so the user/password login prompt is already taken care of. But how do we determine the user from within the code after this. I tried using, System.Security.Principal.WindowsIdentity.GetCurrent().Name.ToString() but this just returned NT AUTHORITY\SYSTEM which is of no real use when I know I typed in TEST1 as the username. :confused: Any help would be gratefully received - Thanks in advance Brian
You must set up impersonation in your Web.config file. See the documentation on the
<identity>
config section in the .NET Framework SDK.Microsoft MVP, Visual C# My Articles
-
Hi I'm new to C# & .Net and the wonderful world of web services so forgive me if this is a simple and/or stupid question :doh: The WebService we are writing needs to determine which user is using it. We are using Digest Authentication (thus handled by Windows before it hits the service) so the user/password login prompt is already taken care of. But how do we determine the user from within the code after this. I tried using, System.Security.Principal.WindowsIdentity.GetCurrent().Name.ToString() but this just returned NT AUTHORITY\SYSTEM which is of no real use when I know I typed in TEST1 as the username. :confused: Any help would be gratefully received - Thanks in advance Brian
In you case I think windows has Authenticated your user and it is using NT AUTHORITY\SYSTEM to run your code.You have to use impersonation so that when you use that code line you will get correct user. Second solution could be to implement IPrincipal and explicitly set user information. Education is no substitute for intelligence. That elusive quality is defined only in part by puzzle-solving ability. It is in the creation of new puzzles reflecting what your senses report that you round out the definition. Frank Herbert
-
In you case I think windows has Authenticated your user and it is using NT AUTHORITY\SYSTEM to run your code.You have to use impersonation so that when you use that code line you will get correct user. Second solution could be to implement IPrincipal and explicitly set user information. Education is no substitute for intelligence. That elusive quality is defined only in part by puzzle-solving ability. It is in the creation of new puzzles reflecting what your senses report that you round out the definition. Frank Herbert
Hi thanks for your reply. I seem to have found a solution by using Context.User.Identity.Name which returns the userid I was expecting of it Thanks once again