C# claimsResponse始终返回Null

C# claimsResponse始终返回Null,c#,dotnetopenauth,C#,Dotnetopenauth,您好,我在asp.net中有以下代码。我已将DotNetOpenAuth.dll用于openID。代码正在修改中 protected void openidValidator_ServerValidate(object source, ServerValidateEventArgs args) { // This catches common typos that result in an invalid OpenID Identifier. args.I

您好,我在asp.net中有以下代码。我已将DotNetOpenAuth.dll用于openID。代码正在修改中

protected void openidValidator_ServerValidate(object source, ServerValidateEventArgs args)
    {
        // This catches common typos that result in an invalid OpenID Identifier.
        args.IsValid = Identifier.IsValid(args.Value);
    }

    protected void loginButton_Click(object sender, EventArgs e)
    {
        if (!this.Page.IsValid)
        {
            return; // don't login if custom validation failed.
        }
        try
        {
            using (OpenIdRelyingParty openid = this.createRelyingParty())
            {
                IAuthenticationRequest request = openid.CreateRequest(this.openIdBox.Text);

                // This is where you would add any OpenID extensions you wanted
                // to include in the authentication request.
                ClaimsRequest objClmRequest = new ClaimsRequest();
                objClmRequest.Email = DemandLevel.Request;
                objClmRequest.Country = DemandLevel.Request;
                request.AddExtension(objClmRequest);

                // Send your visitor to their Provider for authentication.
                request.RedirectToProvider();
            }
        }
        catch (ProtocolException ex)
        {
            this.openidValidator.Text = ex.Message;
            this.openidValidator.IsValid = false;
        }
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        this.openIdBox.Focus();
        if (Request.QueryString["clearAssociations"] == "1")
        {
            Application.Remove("DotNetOpenAuth.OpenId.RelyingParty.OpenIdRelyingParty.ApplicationStore");

            UriBuilder builder = new UriBuilder(Request.Url);
            builder.Query = null;
            Response.Redirect(builder.Uri.AbsoluteUri);
        }

        OpenIdRelyingParty openid = this.createRelyingParty();
        var response = openid.GetResponse();
        if (response != null)
        {
            switch (response.Status)
            {
                case AuthenticationStatus.Authenticated:
                    // This is where you would look for any OpenID extension responses included
                    // in the authentication assertion.
                    var claimsResponse = response.GetExtension<ClaimsResponse>();
                    State.ProfileFields = claimsResponse;
                    // Store off the "friendly" username to display -- NOT for username lookup
                    State.FriendlyLoginName = response.FriendlyIdentifierForDisplay;
                    // Use FormsAuthentication to tell ASP.NET that the user is now logged in,
                    // with the OpenID Claimed Identifier as their username.
                    FormsAuthentication.RedirectFromLoginPage(response.ClaimedIdentifier, false);
                    break;
                case AuthenticationStatus.Canceled:
                    this.loginCanceledLabel.Visible = true;
                    break;
                case AuthenticationStatus.Failed:
                    this.loginFailedLabel.Visible = true;
                    break;

                // We don't need to handle SetupRequired because we're not setting
                // IAuthenticationRequest.Mode to immediate mode.
                ////case AuthenticationStatus.SetupRequired:
                ////    break;
            }
        }
    }

    private OpenIdRelyingParty createRelyingParty()
    {
        OpenIdRelyingParty openid = new OpenIdRelyingParty();
        int minsha, maxsha, minversion;
        if (int.TryParse(Request.QueryString["minsha"], out minsha))
        {
            openid.SecuritySettings.MinimumHashBitLength = minsha;
        }
        if (int.TryParse(Request.QueryString["maxsha"], out maxsha))
        {
            openid.SecuritySettings.MaximumHashBitLength = maxsha;
        }
        if (int.TryParse(Request.QueryString["minversion"], out minversion))
        {
            switch (minversion)
            {
                case 1: openid.SecuritySettings.MinimumRequiredOpenIdVersion = ProtocolVersion.V10; break;
                case 2: openid.SecuritySettings.MinimumRequiredOpenIdVersion = ProtocolVersion.V20; break;
                default: throw new ArgumentOutOfRangeException("minversion");
            }
        }
        return openid;
    }
protectedvoid openidValidator\u ServerValidate(对象源,ServerValidateEventArgs args)
{
//这将捕获导致无效OpenID标识符的常见键入错误。
args.IsValid=标识符.IsValid(args.Value);
}
受保护的无效登录按钮单击(对象发送者,事件参数e)
{
如果(!this.Page.IsValid)
{
return;//如果自定义验证失败,则不登录。
}
尝试
{
使用(OpenIdRelyingParty openid=this.createRelyingParty())
{
IAAuthenticationRequest=openid.CreateRequest(this.openIdBox.Text);
//您可以在这里添加所需的任何OpenID扩展
//包括在身份验证请求中。
ClaimsRequest objClmRequest=新的ClaimsRequest();
objClmRequest.Email=DemandLevel.Request;
objClmRequest.Country=DemandLevel.Request;
请求。追加扩展(objClmRequest);
//将访问者发送给他们的提供商进行身份验证。
request.redirectTopProvider();
}
}
捕获(协议例外)
{
this.openidValidator.Text=ex.Message;
this.openidValidator.IsValid=false;
}
}
受保护的无效页面加载(对象发送方、事件参数e)
{
this.openIdBox.Focus();
if(Request.QueryString[“clearAssociations”]=“1”)
{
Application.Remove(“DotNetOpenAuth.OpenId.RelyingParty.OpenIdRelyingParty.ApplicationStore”);
UriBuilder=新的UriBuilder(Request.Url);
builder.Query=null;
重定向(builder.Uri.AbsoluteUri);
}
OpenIdRelyingParty openid=this.createRelyingParty();
var response=openid.GetResponse();
if(响应!=null)
{
开关(响应状态)
{
案例验证状态。已验证:
//您可以在这里查找包含的任何OpenID扩展响应
//在身份验证断言中。
var claimsResponse=response.GetExtension();
State.ProfileFields=索赔响应;
//存储要显示的“友好”用户名--不用于用户名查找
State.FriendlyLoginName=response.FriendlyIdentifierForDisplay;
//使用FormsAuthentication告诉ASP.NET用户现在已登录,
//使用OpenID声明的标识符作为其用户名。
FormsAuthentication.RedirectFromLoginPage(response.ClaimedIdentifier,false);
打破
案例身份验证状态。已取消:
this.logincanceledbalel.Visible=true;
打破
案例身份验证状态。失败:
this.loginFailedLabel.Visible=true;
打破
//我们不需要处理SetupRequired,因为我们没有设置
//IAAuthenticationRequest.Mode转换为立即模式。
////案例身份验证状态。需要设置:
////中断;
}
}
}
私有OpenIdRelyingParty createRelyingParty()
{
OpenIdRelyingParty openid=新OpenIdRelyingParty();
内明沙、马克沙、明版本;
if(int.TryParse(Request.QueryString[“minsha”],out minsha))
{
openid.SecuritySettings.MinimumHashBitLength=minsha;
}
if(int.TryParse(Request.QueryString[“maxsha”],out maxsha))
{
openid.SecuritySettings.MaximumHashBitLength=maxsha;
}
if(int.TryParse(Request.QueryString[“minversion”],out-minversion))
{
开关(最小版本)
{
案例1:openid.SecuritySettings.MinimumRequiredOpenIdVersion=ProtocolVersion.V10;中断;
案例2:openid.SecuritySettings.MinimumRequiredOpenIdVersion=ProtocolVersion.V20;中断;
默认值:抛出新ArgumentOutOfRangeException(“minversion”);
}
}
返回openid;
}
对于上面的代码,我总是得到

var claimsResponse = response.GetExtension<ClaimsResponse>();
var-claimsResponse=response.GetExtension();

我总是得到claimsResponse=null。它发生的原因是什么。对于RelyingParty,类似openid的域验证是否有任何要求??请尽快给我答复。

这是一份:。这篇文章提供了更多的细节,但在我们讨论时仍然…

:为什么这是一个答案而不是评论P(我投票决定结束另一个问题,因为这个问题的信息量更大)