I am using the ASP.NET Membership provider for username/password
authentication with my WCF service, and this authentication process is
working fine, however I am unable to obtain the authenticated username within
my WCF service. I need to know the username for database accessing purposes.
I am using the <serviceHostingEnvironment
aspNetCompatibilityEnabled="true"/> in the web.config and
[AspNetCompatibilityRequirements(RequirementsMode =
AspNetCompatibilityRequirementsMode.Required)] attribute on the WCF Service
class. Upon entry to the WCF Service, System.Web.HttpContext.Current is not
null, however System.Web.HttpContext.Current.User.Identity.Name is zero
length and System.Web.HttpContext.Current.User.Identity.IsAuthenticated ==
false.
Please HELP....how can I access the authenticated username.
I know ASP.NET Membership authentication is working, because I can change
the password in the client credentials to an invalid value, and the WCF
service fails with security exception.

Signature
Philip
Philip - 07 Mar 2008 16:04 GMT
Hello....is anyone home ?

Signature
Philip
> I am using the ASP.NET Membership provider for username/password
> authentication with my WCF service, and this authentication process is
[quoted text clipped - 15 lines]
> the password in the client credentials to an invalid value, and the WCF
> service fails with security exception.
Tiago Halm - 12 Mar 2008 23:41 GMT
In WCF you can get the authenticated user in one of two ways:
either
ServiceSecurityContext.Current.WindowsIdentity.*
or
OperationContext.Current.ServiceSecurityContext.WindowsIdentity.*
Namespace is System.ServiceModel.
Tiago Halm
>I am using the ASP.NET Membership provider for username/password
> authentication with my WCF service, and this authentication process is
[quoted text clipped - 19 lines]
> the password in the client credentials to an invalid value, and the WCF
> service fails with security exception.
Tiago Halm - 12 Mar 2008 23:48 GMT
Ooops, sorry, I missed the custom username/password. I thought it was
Windows auth. Never tried custom username/password with membership, because
on my scenario I used a username token with a custom authorization scheme
built around Parameter Inspectors. I built a custom service/client
credential so I would be able to delegate token on downstream calls and was
able to have it inside ServiceSecurityContext.Current.PrimaryIdentity.
Don't know if it helps.
Tiago Halm
> In WCF you can get the authenticated user in one of two ways:
> either
[quoted text clipped - 30 lines]
>> the password in the client credentials to an invalid value, and the WCF
>> service fails with security exception.
Philip - 13 Mar 2008 01:43 GMT
Thanks....I already have my question answered....I am using
System.Threading.Thread.CurrentPrincipal.Identity.Name

Signature
Philip
> Ooops, sorry, I missed the custom username/password. I thought it was
> Windows auth. Never tried custom username/password with membership, because
[quoted text clipped - 41 lines]
> >> the password in the client credentials to an invalid value, and the WCF
> >> service fails with security exception.
IliaJ - 25 Mar 2008 17:30 GMT
Strange, System.Web.HttpContext.Current.User.Identity.Name works OK for me in
a simple test project.
> Thanks....I already have my question answered....I am using
> System.Threading.Thread.CurrentPrincipal.Identity.Name
Philip - 25 Mar 2008 21:43 GMT
Can you email me your sample app to plippard@sanibellogic.com ?
Presumably....you are using the Membership provider for authentication ?
Thanks

Signature
Philip
> Strange, System.Web.HttpContext.Current.User.Identity.Name works OK for me in
> a simple test project.
>
> > Thanks....I already have my question answered....I am using
> > System.Threading.Thread.CurrentPrincipal.Identity.Name
Philip - 28 Mar 2008 19:36 GMT
I have reviewed your code.....and your code is working because you are
conducting a separate login step via an attended login web web page.
I am attempting to login at WCF service call time...using the WCF
ClientCredentials set of values within the WCF proxy....as illustrated
below...
ProductsSvc.ProductsSvcClient productsSvcProxy = new
ProductsSvc.ProductsSvcClient();
productsSvcProxy.ClientCredentials.UserName.UserName =
"JackBenny";
productsSvcProxy.ClientCredentials.UserName.Password =
"helloworld";
productsSvcProxy.GetProductListCompleted += new
EventHandler<ProductsSvc.GetProductListCompletedEventArgs>(productsSvc_GetProductListingCompleted);
productsSvcProxy.GetProductListAsync();
I have to examine the System.Threading.Thread.CurrentPrincipal.Identity
value to obtain the Membership Provider logged-in username. I can not get
the Username by looking at the compatibility values....as discussed earlier
in my problem description.

Signature
Philip
> Strange, System.Web.HttpContext.Current.User.Identity.Name works OK for me in
> a simple test project.
>
> > Thanks....I already have my question answered....I am using
> > System.Threading.Thread.CurrentPrincipal.Identity.Name