0

我遇到了关于 openid 的问题,经过身份验证检查后,我没有从谷歌获得完整信息。我需要谷歌的全面回应。我得到空白值。请尝试尽快解决。

我的代码是 -

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Xml;
using System.Xml.XPath;
using DotNetOpenAuth.OpenId;
using DotNetOpenAuth.OpenId.RelyingParty;
using DotNetOpenAuth.OpenId.Extensions.SimpleRegistration;
using DotNetOpenAuth.OpenId.Extensions.AttributeExchange;

public partial class geocode : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        HandleOpenIDProviderResponse();

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        string geoValue = GetLongitudeAndLatitude(TextBox1.Text, "false");
        Label1.Text = geoValue;
    }
    public string GetLongitudeAndLatitude(string address, string sensor)
    {
        string urlAddress = "http://maps.googleapis.com/maps/api/geocode/xml?address=" + HttpUtility.UrlEncode(address) + "&sensor=" + sensor;
        string returnValue = "";
        try
        {
            XmlDocument objXmlDocument = new XmlDocument();
            objXmlDocument.Load(urlAddress);
            XmlNodeList objXmlNodeList = objXmlDocument.SelectNodes("/GeocodeResponse/result/geometry/location");
            foreach (XmlNode objXmlNode in objXmlNodeList)
            {
                // GET LONGITUDE 
                returnValue = objXmlNode.ChildNodes.Item(0).InnerText;

                // GET LATITUDE 
                returnValue += "," + objXmlNode.ChildNodes.Item(1).InnerText;
            }
        }
        catch
        {
            // Process an error action here if needed  
        }
        return returnValue;
    }







    OpenIdRelyingParty openid = new OpenIdRelyingParty();



    protected void HandleOpenIDProviderResponse()
    {
        var response = openid.GetResponse();

        if (response != null)
        {
            switch (response.Status)
            {
                case AuthenticationStatus.Authenticated:
                   // NotLoggedIn.Visible = false;
                    btngmaillogout.Visible = true;

                    var fetchResponse = response.GetExtension<FetchResponse>();
                    Session["FetchResponse"] = fetchResponse;
                    var response2 = Session["FetchResponse"] as FetchResponse;

                    Label2.Text = response2.GetAttributeValue(WellKnownAttributes.Contact.Email);
                    Label3.Text = GetFullname(response2.GetAttributeValue(WellKnownAttributes.Name.First), response2.GetAttributeValue(WellKnownAttributes.Name.Last));
                    Label4.Text = response2.GetAttributeValue(WellKnownAttributes.BirthDate.WholeBirthDate);
                    Label5.Text = response2.GetAttributeValue(WellKnownAttributes.Contact.Phone.Mobile);
                    Label6.Text = response2.GetAttributeValue(WellKnownAttributes.Person.Gender);
                    break;
                case AuthenticationStatus.Canceled:
                    Label1.Text = "Cancelled.";
                    break;
                case AuthenticationStatus.Failed:
                    Label1.Text = "Login Failed.";
                    break;
            }
        }
        else
        {
            return;
        }
    }

    protected void OpenLogin_Click(object src, CommandEventArgs e)
    {
        string discoveryUri = e.CommandArgument.ToString();
        var b = new UriBuilder(Request.Url) { Query = "" };
        var req = openid.CreateRequest(discoveryUri, b.Uri, b.Uri);
        var fetchRequest = new FetchRequest();
        fetchRequest.Attributes.AddRequired(WellKnownAttributes.Contact.Email);
        fetchRequest.Attributes.AddRequired(WellKnownAttributes.Name.First);
        fetchRequest.Attributes.AddRequired(WellKnownAttributes.Name.Last);
        fetchRequest.Attributes.AddRequired(WellKnownAttributes.Person.Gender);
        fetchRequest.Attributes.AddRequired(WellKnownAttributes.Contact.Phone.Mobile);
        fetchRequest.Attributes.AddRequired(WellKnownAttributes.BirthDate.WholeBirthDate);
        req.AddExtension(fetchRequest);
        req.RedirectToProvider();
    }

    private static string GetFullname(string first, string last)
    {
        var _first = first ?? "";
        var _last = last ?? "";
        if (string.IsNullOrEmpty(_first) || string.IsNullOrEmpty(_last))
            return "";
        return _first + " " + _last;
    }

    protected void btngmaillogout_click(object sender, EventArgs e)
    {
        // logout from gmail and return to website default/home page
        Response.Redirect("successlogout.aspx");
    }


}
4

0 回答 0