Tailspin.Surveys.Web.Security.BaseControlContextExtensions.IsSigningUp C# (CSharp) Method

IsSigningUp() static private method

Extension method to see if the current process flow is the sign up process.
static private IsSigningUp ( this context ) : bool
context this BaseControlContext from ASP.NET.
return bool
        internal static bool IsSigningUp(this BaseControlContext context)
        {
            Guard.ArgumentNotNull(context, nameof(context));

            // Note - Due to https://github.com/aspnet/Security/issues/546, we cannot get to the authentication properties
            // from the context in the RedirectToAuthenticationEndpoint event to check for sign up.  This bug is currently
            // slated to be fixed in the RC2 timeframe.  When this is fixed, remove the workaround that checks the HttpContext

            string signupValue;
            object obj;
            // Check the HTTP context and convert to string
            if (context.HttpContext.Items.TryGetValue("signup", out obj))
            {
                signupValue = (string)obj;
            }
            else
            {
                // It's not in the HTTP context, so check the authentication ticket.  If it's not there, we aren't signing up.
                if ((context.AuthenticationTicket == null) ||
                    (!context.AuthenticationTicket.Properties.Items.TryGetValue("signup", out signupValue)))
                {
                    return false;
                }
            }

            // We have found the value, so see if it's valid
            bool isSigningUp;
            if (!bool.TryParse(signupValue, out isSigningUp))
            {
                // The value for signup is not a valid boolean, throw                
                throw new InvalidOperationException($"'{signupValue}' is an invalid boolean value");
            }

            return isSigningUp;
        }
    }
BaseControlContextExtensions