I am trying to create a rule for a WFFM email address field to populate the field with the logged in users email address. But, I am not sure what rule to use or if any of the rules will work at all for the way we have our security set-up.

We are using Active Directory Federated Identity for the log in process.

Here is some sample C# code that sets the logged in user's email address to a UserSession class:

Base Session Class:

public abstract class BaseSession 
    protected static bool ContainsKey(String paramName) {
    bool res = false;
    try {
             if (HttpContext.Current.Session[paramName] != null)
                res = true;
        catch { res = false; }
    return res;

User Session Class:

public class UserSession : BaseSession
    public static string EmailAddress
            if (ContainsKey(RootItems.Keys.EmailAddress))
                return HttpContext.Current.Session[RootItems.Keys.EmailAddress] as string;
            return null;
            HttpContext.Current.Session[RootItems.Keys.EmailAddress] = value;

Setting the Email Address to the UserSession Class:

using System.IdentityModel.Services;
using System.IdentityModel.Tokens;
using System.Security.Claims;

SessionSecurityToken sessionToken = null;
FederatedAuthentication.SessionAuthenticationModule.TryReadSessionTokenFromCookie(out sessionToken);
FederatedAuthentication.SessionAuthenticationModule.AuthenticateSessionSecurityToken(sessionToken, true);
ClaimsPrincipal claimsPrincipal = sessionToken.ClaimsPrincipal;

foreach (var varClaims in claimsPrincipal.Claims)
    if (varClaims.Type.Contains("http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress"))
        UserSession.EmailAddress = varClaims.Value;

Not Sure Which Security Rule to Choose:

enter image description here


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.