2012-01-17 79 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