Login

My company has a great application that we are finishing. It uses WCF as a back-bone with Active Directory for authentication. This works great for one of the two sites, since the authentication model is Windows, and you must be part of the domain to enter the site. The question I have is related to another site that is accessible from the outside. It sets ClientCredentials.Windows.ClientCredential to proxy a call with a specific user / password to impersonate an AD user, so the full security model works. It all works exactly as expected.

The question I have is, on the Internet, I can use HttpContext.Current.User.Identity.Name to get a registered user from the Forms authentication part, but for this I need to make sure that the System.Web link exists against the DLL in which I'm working at the moment. Our base objects are taken from a simplified class that does not know about System.Web. Is there a way to find out the Forms user who is registered within this project of the base object? I tried System.Security.Principal, but it only gives me access to Windows accounts from what I can say and will not do me any good.

I know that the option is to just reference System.Web and do with it, but that sounds really klugy to me, and not the best option, so I hope for some tips here.

+2
source share
2 answers

Thread.CurrentPrincipal.Identity will do the same as HttpContext.CurrentContext...

It will return the identifier associated with the current executable thread, which in most cases is a registered user *.

Note. * If you use delegation / impersonation or act as a service account, it will return the account in which the stream was ever specified, but in your case it does not look like you are doing any kind of context switching identifiers.

+4
source

If the username as a string is enough for you,

 Environment.UserName // Environment.UserDomainName and MachineName can also be useful 

From MSDN :

Gets the name of the user who started the current thread.

+2
source

All Articles