I have an Asp.net application with Forms mode authentication
<authentication mode="Forms">
<forms loginUrl="Login.aspx" />
</authentication>
I have also created an Ajax enabled web service to support a 'vote' function from the page..
<system.serviceModel>
<behaviors>
<endpointBehaviors>
<behavior name="VoteServiceAspNetAjaxBehavior">
<enableWebScript />
</behavior>
</endpointBehaviors>
</behaviors>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true"
multipleSiteBindingsEnabled="true" />
<services>
<service name="VoteService">
<endpoint address="" behaviorConfiguration="VoteServiceAspNetAjaxBehavior"
binding="webHttpBinding" contract="VoteService" />
</service>
</services>
in the service implementation, I need to get at the asp identity in order to figure out who is voting...
[OperationContract]
public int VoteForComment(Guid commentId)
{
string UserName = ServiceSecurityContext.Current.PrimaryIdentity.Name;
//...
}
But even after logging in to the asp application , the ServiceSecurityContext.Current is null.
Is it possible to configure the web service so that it can share the asp identity? Alternately, is it possible to figure out the current user another way?
Edit Turns out really easy, the aspNetCompatabilityEnabled="true" means that the web service has access to all the normal state available in Asp.Net, I just had to use the System.Web namespace.... System.Web.HttpContext.Current.User.Identity.Name