2009-05-19 62 views
2

我想設置我的代碼來請求來自OpenID服務提供商的一些屬性。同時,我希望返回一個ActionResult。有問題的屬性和DotNetOpenID

下面是開放ID樣品MVC項目中的代碼(即自帶直出DotNetOpenId/DotNetOpenAuth網站)...

try 
{ 
    return openid.CreateRequest(Request.Form["openid_identifier"]) 
     .RedirectingResponse 
     .AsActionResult(); 
} 
catch (ProtocolException ex) 
{ ... } 

這是偉大的,但它並沒有告訴我任何請求或可選必需的屬性。 所以,我已經試過以下(我自己的,未經檢驗pseduo上下的代碼)....

var fetch = new FetchRequest(); 
fetch.Attributes.AddRequired(WellKnownAttributes.Contact.Email); 
fetch.Attributes.AddRequired(WellKnownAttributes.Name.FullName); 
fetch.Attributes.AddRequired(WellKnownAttributes.Name.Alias); 
fetch.Attributes.AddRequired(WellKnownAttributes.Preferences.Language); 
fetch.Attributes.AddRequired(WellKnownAttributes.Preferences.TimeZone); 
fetch.Attributes.AddRequired(WellKnownAttributes.Person.Gender); 

openId.CreateRequest(identifier.ToString()).AddExtension(fetch); 

這也似乎罰款。但是...我不知道如何現在要求的結果是一個ActionResult()...

我如何創建一個openId.CreateRequest,允許我定義一些必需的屬性並返回一個ActionView?

回答

1

你做得很好。結合這兩種方法。

撥打IAuthenticationRequest.AddExtension只需撥打IAuthenticationRequest.RedirectingResponse.AsActionResult()即可。

try 
{ 
    var request = openid.CreateRequest(Request.Form["openid_identifier"]); 

    var fetch = new FetchRequest(); 
    fetch.Attributes.AddRequired(WellKnownAttributes.Contact.Email); 
    fetch.Attributes.AddRequired(WellKnownAttributes.Name.FullName); 
    fetch.Attributes.AddRequired(WellKnownAttributes.Name.Alias); 
    fetch.Attributes.AddRequired(WellKnownAttributes.Preferences.Language); 
    fetch.Attributes.AddRequired(WellKnownAttributes.Preferences.TimeZone); 
    fetch.Attributes.AddRequired(WellKnownAttributes.Person.Gender); 
    request.AddExtension(fetch); 

    return request.RedirectingResponse.AsActionResult(); 
} 
catch (ProtocolException ex) 
{ ... } 
+0

hmm。這就是我想的(最初嘗試過),但智能感知顯示錯誤。我的代碼在家,所以今晚我會檢查一下。我也確定我正在使用最新的版本。再次歡呼安德魯:) – 2009-05-20 02:44:01