0

当我尝试在代码页下方成功加载时,关于谷歌身份验证的这个问题,但是当我点击谷歌登录按钮时,在调试此行显示错误时。

错误在

GetExtension<FetchResponse>() 

在线的

Var fetchResponse = Response.GetExtension<FetchResponse>()

那么这一行有什么问题..我尝试搜索这个问题,但我没有得到它的解决方案

protected void Page_Load(object sender, EventArgs e)
    {
        OpenIdRelyingParty rp = new OpenIdRelyingParty();
        var r = rp.GetResponse();
        if (r != null)
        {
            switch (r.Status)
            {
                case AuthenticationStatus.Authenticated:
                    NotLoggedIn.Visible = false;
                    Session["GoogleIdentifier"] = r.ClaimedIdentifier.ToString();
                    Response.Redirect("Default4.aspx"); //redirect to main page of your website  
                    var fetchResponse = Response.GetExtension<FetchResponse>();
                    Session["FetchResponse"] = fetchResponse;
                    var response2 = Session["FetchResponse"] as FetchResponse;
                    // Use FormsAuthentication to tell ASP.NET that the user is now logged in,
                    // with the OpenID Claimed Identifier as their username.
                    string uname = response2.GetAttributeValue(WellKnownAttributes.Name.First) ?? "Guest";
                    FormsAuthentication.RedirectFromLoginPage(uname, false);   //(response.ClaimedIdentifier, false);
                    break;

                case AuthenticationStatus.Canceled:
                    lblAlertMsg.Text = "Cancelled.";
                    break;

                case AuthenticationStatus.Failed:
                    lblAlertMsg.Text = "Login Failed.";
                    break;
            }
        }
    }

    protected void OpenLogin_Click(object src, CommandEventArgs e)
    {
        string discoveryUri = e.CommandArgument.ToString();
        OpenIdRelyingParty openid = new OpenIdRelyingParty();
        var b = new UriBuilder(Request.Url) { Query = "" };
        //var req = openid.CreateRequest(discoveryUri, b.Uri, b.Uri);


        //var req = openid.CreateRequest(discoveryUri, b.Uri, b.Uri);
        var req = openid.CreateRequest(discoveryUri);

        // This is where you would add any OpenID extensions you wanted
        // to include in the authentication request. In this case, we are making use of OpenID Attribute Exchange 1.0
        // to fetch additional data fields from the OpenID Provider
        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.Contact.HomeAddress.Country);
        req.AddExtension(fetchRequest);


        req.RedirectToProvider();

    }
4

1 回答 1

1

它应该是

var fetchResponse = r.GetExtension<FetchResponse>();

代替

var fetchResponse = Response.GetExtension<FetchResponse>();
于 2012-08-21T12:38:42.237 回答