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 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
Gowtham CpPosted Aug 21, 2024, 3:08 AM
Improved version of your method:
This function checks if a user is logged in. If so, it returns a tuple with
true, their role, and login ID. If not, it redirects them to the login page and returnsfalsewith empty values.Hope it helps!
Jignesh KumarPosted Aug 21, 2024, 3:57 AM
Hello Ramco,
You can use below code to check in you PageLoad,
Amit MohantyPosted Aug 19, 2024, 6:43 AM
Check this: