Hi
I have below cod but tuple is returning nothing. I want User Id, & Role value
Web.Config
Login Form
**********
bool success = (bool)successParam.Value;
if (success)
{
Response.Redirect("~/Admin/Department.aspx");
}
else
{
//ShowMessage("Oops...", success.ToString(), "error");
}
Department
**********
var authenticatedUser = Common.CommonFunction.AuthenticatedUser();
if (authenticatedUser.Item1) // Check if the user is authenticated
{
var userRole = authenticatedUser.Item2;
var loginId = authenticatedUser.Item3;
}
else
{
// Handle unauthenticated scenario if needed
}
AuthenticatedUser
*****************
public static Tuple AuthenticatedUser()
{
try
{
if (HtpContext.Current.User.Identity.IsAuthenticated)
{
FormsIdentity id = (FormsIdentity)HtpContext.Current.User.Identity;
FormsAuthenticationTicket ticket = id.Ticket;
return Tuple.Create(true, ticket.UserData, HtpContext.Current.User.Identity.Name);
}
else
{
FormsAuthentication.RedirectToLoginPage();
return Tuple.Create(false, string.Empty, string.Empty);
}
}
catch (Exception ex)
{
FormsAuthentication.RedirectToLoginPage();
return Tuple.Create(false, string.Empty, string.Empty);
}
}
Thanks
Gowtham CpPosted Aug 19, 2024, 4:49 PM
It seems like the issue might be that roles aren’t being saved in
ticket.UserData, or the redirection withFormsAuthentication.RedirectToLoginPageis causing problems. Double-check that you’re storing roles correctly when the user logs in. Try commenting out the redirection temporarily to see if that helps you get the user data. Once you confirm the user is logged in, you should be able to retrieve their role and ID from theauthenticatedUsertuple.