Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

i have created the WCF service for sharepoint connection. This service hosted on Sharepoint server. Pool account is the SP Admin.

For the form authentication we are using the below code

private SecurityToken GetSecurityToken(string userName, string password)
    {
        SecurityToken token = null;
        SPIisSettings iisSettings = IisSettings;
        Uri appliesTo = ApplicationUri;

        if (string.IsNullOrEmpty(userName) ||
            string.IsNullOrEmpty(password))
            return null;

        SPFormsAuthenticationProvider authProvider = iisSettings.FormsClaimsAuthenticationProvider;
        token = SPSecurityContext.SecurityTokenForFormsAuthentication(
            appliesTo,
            authProvider.MembershipProvider,
            authProvider.RoleProvider,
            userName,
            password);

        return token;
    }

    private void EstablishSessionWithToken(SecurityToken securityToken)
    {
        using (SPSite site = new SPSite(ApplicationUri.ToString()))
        {
            using (SPWeb web = site.OpenWeb())
            {
                if (null == securityToken)
                {
                    throw new ArgumentNullException("securityToken");
                }

                SPFederationAuthenticationModule fam = SPFederationAuthenticationModule.Current;

                if (null == fam)
                {
                    throw new ArgumentException(null, "FederationAuthenticationModule");
                }

                fam.SetPrincipalAndWriteSessionToken(sessionToken, true);
            }
        }
    }

Till the SecurityToken code is working fine. But when i am trying to EstablishSessionWithToken its shows me an error as

Exception of type 'System.ArgumentException' was thrown. Parameter name: FederationAuthenticationModule

After i diagnostic i found that SPFederationAuthenticationModule.Current is null.

Can anybody help to find out the resolution...

Thanks in advance

share|improve this question
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.