I am calling WCF from an ASP.NET page using ASP.NET Ajax. I am using Forms Authentication to secure the website.
Everything was working as expected through development until it was deployed onto the production server then I started getting javascript errors because the service could not be found. The production server is using SSL so I added the following to my web.config
<webHttpBinding>
<binding name="webBinding">
<security mode="Transport" />
</binding>
</webHttpBinding>
This stopped the javascript errors from occurring but now the WCF service does not behave as it use to.
Before setting security to Transport a call to the WCF service from ASP.NET Ajax would execute the Application_AuthenticateRequest in my Global.asax. This would setup a custom IPrinciple on HttpContext.Current.User based on the Forms Authentication ticket. The constructor for my WCF service sets Thread.CurrentPrinciple = HttpContext.Current.User so my service has access to the IPrinciple set during Application_AuthenticateRequest.
After changing the security to Transport it does not appear to be running through Application_AuthenticateRequest because my Thread.CurrentPrinciple is not my custom IPrinciple.
Does anyone know how I can get the same behavior as before using Transport as after using Transport?
My webpage is using the following to reference the WCF service:
<asp:ScriptManagerProxy ID="ScriptManagerProxy1" runat="
<Services>
<asp:ServiceReference Path="~/Services/MyService.svc" />
</Services>
</asp:ScriptManagerProxy>
Code used in my Application_AuthenticateRequest:
protected void Application_AuthenticateRequest(object sender, EventArgs e)
{
String cookieName = FormsAuthentication.FormsCookieName;
HttpCookie authCookie = Context.Request.Cookies[cookieName];
if (authCookie == null)
{
return;
}
FormsAuthenticationTicket authTicket = null;
try
{
authTicket = FormsAuthentication.Decrypt(authCookie.Value);
}
catch
{
return;
}
if (authTicket == null)
{
return;
}
HttpContext.Current.User = new CustomPrinciple(authTicket.Name);
}