2012-01-17 81 views
7

我一直在嘗試使用ASP.Net MVC 4開發人員預覽DotNetOpenAuth示例。DotNetOpenAuth與MVC 4.0

我可以成功地調用我的行動從我的測試頁面,但碰到一個奇怪的問題的代碼,因爲的一行:

var request = _openid.CreateRequest(openIdUrl); 
    var fetch = new FetchRequest(); 
    fetch.Attributes.AddRequired(WellKnownAttributes.Contact.Email); 
    fetch.Attributes.AddRequired(WellKnownAttributes.Name.First); 
    fetch.Attributes.AddRequired(WellKnownAttributes.Name.Last); 
    request.AddExtension(fetch); 
    //return RedirectToAction("Login"); 
    return request.RedirectingResponse.AsActionResult(); // <-- This is the line throwing the error 

如果我註釋掉的代碼有問題的行,並取消在此之前的一個,我再也看不到運行時錯誤了。

到目前爲止,我曾嘗試:

1)確保我有正確的重定向:

<runtime> 
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> 
     <dependentAssembly> 
      <assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35" /> 
      <bindingRedirect oldVersion="1.0.0.0" newVersion="2.0.0.0" /> 
     </dependentAssembly> 
     <dependentAssembly> 
      <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" /> 
      <bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.0.0.0" /> 
     </dependentAssembly> 
     <dependentAssembly> 
      <assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" /> 
      <bindingRedirect oldVersion="1.0.0.0" newVersion="2.0.0.0" /> 
      <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" /> 
     </dependentAssembly> 
    </assemblyBinding> 
    <legacyHMACWarning enabled="0" /> 
</runtime> 

2)具有正確的命名空間:

using DotNetOpenAuth.OpenId.Extensions.AttributeExchange; 
using DotNetOpenAuth.OpenId.Extensions; 

這在我看來, DotNetOpenAuth dll是針對MVC V 1.0.0編譯的,綁定重定向不是工作,或者擴展方法可能是針對不推薦使用的方法。

MVC版本:4.0.0.0 DotNetOpenAuth版本:3.4.7.11121

上得到這個與MVC 4個工作任何幫助將不勝感激。 的MVC錯誤屏幕圖像下面進一步:

Image of Error Screen

更新 我發現AsActionResult是問題的原因,也許是因爲擴展方法是不能與.NET 4.0兼容。我可以從request.RedirectingResponse中獲得OutgoingWebResponse對象,但知道如何將其轉換爲ActionResult

+0

是你的示例代碼,讓我可以看到OpenId與MVC4一起工作。當我調用提供程序按鈕時,我遇到了很多從圖像路徑到JS錯誤的問題。 – Picflight 2012-01-31 07:35:31

回答

6

看起來您的綁定重定向已損壞。注意System.Web.Mvc如何出現兩次?嘗試刪除第二個,因爲第一個看起來是正確的。是的,DNOA是針對MVC 1.0構建的,並且這是通過設計使其可以針對所有版本的MVC(給定適當的重定向)。這純粹是一個MVC版本的東西 - 不是.NET 4.0的東西。

+0

你的眼睛非常敏銳。謝謝!!我以爲我瘋了。 – 2012-01-17 15:55:48

+0

謝謝謝謝謝謝:) ..我得到同樣的問題,對於mvc3,這對我有用「」。 – labroo 2012-03-14 18:05:19