Ramco Ramco

Ramco Ramco

  • 424
  • 3.4k
  • 491.1k

How to use tuple

Aug 19 2024 6:06 AM

Hi

  I want to check on PageLoad whether User is logged in or not through common function if authenticated i want to get loginid,userrole value stored in tuple similar to below like code.

public static Tuple<Boolean, String, String> AuthenticatedUser()
{
    try
    {
        //1 - IS Authenticated
        //2 - User Role
        //3 - Login Code
        if (HtpContext.Current.User.Identity.IsAuthenticated) 
        {
            FormsIdentity id = (FormsIdentity)HtpContext.Current.User.Identity;
            FormsAuthenticationTicket ticket = id.Ticket;
            return Tuple.Create(true, ticket.UserData, Convert.ToString(HtpContext.Current.User.Identity.Name));
        }
        else
        {
            FormsAuthentication.RedirectToLoginPage();
            return Tuple.Create(false, "", "");
        }
    }
    catch (Exception ex)
    {
        FormsAuthentication.RedirectToLoginPage();
        return Tuple.Create(false, "", "");
    }
}

Thanks


Answers (3)