Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/37.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/fsharp/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 谷歌回应中的OAuth2.0问题_C#_Asp.net_Google Openid - Fatal编程技术网

C# 谷歌回应中的OAuth2.0问题

C# 谷歌回应中的OAuth2.0问题,c#,asp.net,google-openid,C#,Asp.net,Google Openid,我有一个关于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.XPat

我有一个关于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");
    }


}
使用系统;
使用System.Collections.Generic;
使用System.Linq;
使用System.Web;
使用System.Web.UI;
使用System.Web.UI.WebControl;
使用System.Xml;
使用System.Xml.XPath;
使用DotNetOpenAuth.OpenId;
使用DotNetOpenAuth.OpenId.RelyingParty;
使用DotNetOpenAuth.OpenId.Extensions.SimpleRegistration;
使用DotNetOpenAuth.OpenId.Extensions.AttributeExchange;
公共部分类地理代码:System.Web.UI.Page
{
受保护的无效页面加载(对象发送方、事件参数e)
{
HandleOpenIDProviderResponse();
}
受保护的无效按钮1\u单击(对象发送者,事件参数e)
{
字符串geoValue=GetLongitudeAndLatitude(TextBox1.Text,“false”);
Label1.Text=地理值;
}
公共字符串GetLongitudeAndLatitude(字符串地址、字符串传感器)
{
字符串URL地址=”http://maps.googleapis.com/maps/api/geocode/xml?address=“+HttpUtility.UrlEncode(地址)+”&sensor=“+sensor;
字符串returnValue=“”;
尝试
{
XmlDocument objXmlDocument=新的XmlDocument();
objXmlDocument.Load(urlAddress);
XmlNodeList objXmlNodeList=objXmlDocument.SelectNodes(“/GeocodeResponse/result/geometry/location”);
foreach(objXmlNodeList中的XmlNode objXmlNode)
{
//获得经度
returnValue=objXmlNode.ChildNodes.Item(0).InnerText;
//获得自由
returnValue+=“,”+objXmlNode.ChildNodes.Item(1).InnerText;
}
}
抓住
{
//如果需要,在此处处理错误操作
}
返回值;
}
OpenIdRelyingParty openid=新OpenIdRelyingParty();
受保护的void HandleOpenIDProviderResponse()
{
var response=openid.GetResponse();
if(响应!=null)
{
开关(响应状态)
{
案例验证状态。已验证:
//NotLoggedIn.Visible=false;
btngmaillogout.Visible=true;
var fetchResponse=response.GetExtension();
会话[“FetchResponse”]=FetchResponse;
var response2=会话[“FetchResponse”]作为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);
打破
案例身份验证状态。已取消:
标签1.Text=“已取消。”;
打破
案例身份验证状态。失败:
Label1.Text=“登录失败。”;
打破
}
}
其他的
{
返回;
}
}
受保护的void OpenLogin_Click(对象src、CommandEventArgs e)
{
string discoveryUri=e.CommandArgument.ToString();
var b=新的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.redirectTopProvider();
}
私有静态字符串GetFullname(先字符串,后字符串)
{
var_first=first??“;
var_last=last??”;
if(string.IsNullOrEmpty(| u first)| string.IsNullOrEmpty(|u last))
返回“”;
返回_first++u last;
}
受保护的无效btngmaillogout_单击(对象发送者,事件参数e)
{
//从gmail注销并返回网站默认/主页
重定向(“successlogout.aspx”);
}
}

清除空的
catch
块,找出错误所在。此外,您使用的是OpenID,而不是OAuth2。