I'm trying to verify the group of the user while logging in. But when I try to use isManager = site.IsCurrentUserMemberOfGroup(managerGroup.ID); it gives me an error that you don't have an access to the page.
If I'm already logged in and then run the similar code, it runs fine but while using this in login page where the user is not logged in, this code doesn't work and gives the access denied error.
How should I resolve this?
CODE:
SPWeb site = SPControl.GetContextWeb(System.Web.HttpContext.Current);
SPContext currentContext = SPContext.Current;
SPSecurity.RunWithElevatedPrivileges(delegate()
{ SPGroup managerGroup = site.Groups["DevTest"];
bool isManager = site.IsCurrentUserMemberOfGroup(managerGroup.ID);
if (!isManager)
{
Label1.Text = "Wroung user id or group";
}
else
{
bool status = SPClaimsUtility.AuthenticateFormsUser(Context.Request.UrlReferrer, TextBox1.Text, TextBox2.Text);
if (!status)
{
Label1.Text = "wrong user id or password";
}
else
{ Label1.Text = "wrong user id or password";
}
}
});
}
}