I have a WCF service, which is hosted inside of an ASP.NET MVC application (as described in http://msdn.microsoft.com/en-us/library/aa702682.aspx). Part of the MVC actions and WCF service operations are protected, and I use ASP.NET Forms Authentication for both:
// protected MVC action
[Authorize]
public ActionResult ProtectedMvcAction(string args)
// protected WCF operation
[PrincipalPermission(SecurityAction.Demand, Role = "User")]
public void ProtectedWcfOperation(string args)
My WCF client makes sure that the Forms Authentication .ASPXAUTH
cookie gets transmitted to the server on every WCF call.
This worked very well for a long time. Now I'm adding HTTPS
encryption to my server using an SSL
certificate. This required me to make the following changes to the Web.config`:
<basicHttpBinding>
<binding name="ApiServiceBinding">
<security mode="Transport">
<transport clientCredentialType="None" />
</security>
</binding>
</basicHttpBinding>
The service gets activated and the client can invoke the server operations. However, the [PrincipalPermission]
attribute in front of the protected server operations suddenly blocks all service calls. I found out the following:
- In the HTTP case (without
<security mode="Transport">
), bothThread.CurrentPrincipal
andHttpContext.Current.User
are set to aRolePrincipal
instance, with aFormsIdentity
instance in theRolePrincipal.Identity
property. In this case, everything works fine. - In the HTTPS case (with
<security mode="Transport">
in the web.config), the propertyHttpContext.Current.User
is still set to theRolePrincipal/FormsIdentity
combination. But, the propertyThread.CurrentPrincipal
is suddenly set toWindowsPrincipal/WindowsIdentity
instances, which makes the[PrincipalPermission]
attribute throw an exception.
I tried the following:
- Changed the
AppDomain.CurrentDomain.SetPrincipalPolicy
to every possible value (inGlobal.asax
'sApplication_Start
), but that did not change anything. - Set the property
Thread.CurrentPrincipal
inApplication_PostAuthenticate
, but betweenApplication_PostAuthenticate
and the actual service invoke, theThread
'sCurrentPrincipal
is changed to aWindowsPrincipal
again.
Any hints? What am I doing wrong?