I am assuming you are using SharePoint client object model to query the data from SharePoint list.
You might have to pass the credentials to the client context.Check if the below code works!
if (isForms)
{
context.AuthenticationMode = ClientAuthenticationMode.FormsAuthentication;
FormsAuthenticationLoginInfo fba = new FormsAuthenticationLoginInfo(userName, password);
context.FormsAuthenticationLoginInfo = fba;
}
else
{
context.Credentials = new NetworkCredential(userName, password);
}