Thread.CurrentPrincipal resets during application execution.
WCF Ria services Thread.CurrentPrincipal shows empty generic identity while serialization of entities.
06-23-2011 7:49 PM | LINK
I am using WCF RIA services Beta version. I have implemented role based security by creating a CustomPrincipal and CustomIdentity. I am using Forms authentication and Authentication Service provided by WCF RIA services framework. If authentication
succeeds at the server I create CustomIdentity and CustomPrincipal and then add it to the HttpContext.Current.Session for using it in further requests.
HttpContext.Current.Session["CustomPrincipal"] = new CustomPrincipal(new CustomIdentity("authenticatedusername"));
Now for further requests I have created a base class which inherits from DomainService. In the constructor I am writing following code
Thread.CurrentPrincipal = HttpContext.Current.Session["CustomPrincipal"];
Now in my entities I use this as
public class MyEntity
{
public string Username
{
get
{
return Thread.CurrentPrincipal.Identity.Name;
}
}
}
and my domain services return the list of entities as below
[Query]
public List<MyEntity> SelectAll()
{
...
}
The problem is that above code works perfectly fine on local machines, dev servers (Windows 2003 server, iis6, dual core amd opteron), qa servers (Windows 2008 server standard edition, iis7, Quad Core AMD opteron) but fails in production servers
( Windows 2008 server Enterprise edition, iis 7, Intel Xeon CPU ( 2 processor)).
The code in bold above always returns string.Empty. Thread.CurrentPrincipal always returns unauthenticated GenericIdentity.
Gaurave Sehgal
June 23rd, 2011 2:56pm
Hi,
As this issue is not related to Windows server, I suggest discussing it in the right forum. They are the best resource to answer your question.
http://forums.silverlight.net/forums/53.aspx
BrentPlease remember to click Mark as Answer on the post that helps you, and to click Unmark as Answer if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.
Free Windows Admin Tool Kit Click here and download it now
June 23rd, 2011 10:46pm