PDA

View Full Version : حرفه ای: ورود به سایت با گوگل



Mohammad_dn
دوشنبه 23 بهمن 1396, 18:27 عصر
سلام من میخوام با گوگل تو سایتم لوگ این کنم..تنها مشکلی که هست اینه که وقتی به سایت بر میگرده خطای زیر رو میده:

Cannot convert object of type 'System.String' to type '?2?.?3?.?5?'

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.InvalidOperationException: Cannot convert object of type 'System.String' to type '?2?.?3?.?5?'

Source Error:



Line 1175: string code = Request.QueryString["code"];
Line 1176:
Line 1177: string json = GoogleConnect.Fetch("me", code);
Line 1178: GoogleProfile profile = new JavaScriptSerializer().Deserialize<GoogleProfile>(json);
Line 1179: GoogleConnect.Clear(Request.QueryString["code"].ToString());






کد مربوط به لوگ این:



[HttpGet]
[Route("LoginGoogle")]
public void LoginGoogle()
{
GoogleConnect.ClientId = "482352026499-51empr7iklqakhf4d1tjpkr0uj5lhdj4.apps.googleuserco ntent.com";
GoogleConnect.ClientSecret = "7FwT1OefVxpofym32R3fL0td";

GoogleConnect.RedirectUri = "http://localhost:8089";

if (!string.IsNullOrEmpty(Request.QueryString["code"]))
{
string code = Request.QueryString["code"];

string json = GoogleConnect.Fetch("me", code);
GoogleProfile profile = new JavaScriptSerializer().Deserialize<GoogleProfile>(json);
GoogleConnect.Clear(Request.QueryString["code"].ToString());
string name = profile.DisplayName;
string Email = profile.Emails.Find(email => email.Type == "account").Value;
SysAction.User us = new SysAction.User();
if (us.GetIsEmail(Email) == false)
{
Response.Write("<script>alert('این ایمیل قبلا ثبت شده است');location='/Login';</script>");

}
else if (us.GetIsEmail(Email, true) == false)
{

FormsAuthentication.RedirectFromLoginPage(Email, false);
}
else
{
if (us.SaveUser(Email, "", Email, name, 0, "", true) == true)
{

FormsAuthentication.RedirectFromLoginPage(Email, false);
}
else
{
Response.Write("<script>alert('خطا');location='/Login';</script>");
}

}
}
if (Request.QueryString["error"] == "access_denied")
{
Response.Write("<script>alert('خطا');location='/Login';</script>");
}
}
private class GoogleProfile
{
public string Id { get; set; }
public string DisplayName { get; set; }
public List<Email> Emails { get; set; }
public string Gender { get; set; }
}

private class Email
{
public string Value { get; set; }
public string Type { get; set; }
}

Mohammad_dn
دوشنبه 23 بهمن 1396, 22:51 عصر
مشکل حل شد