我一直在尝试使用ASP.Net MVC 4 Developer Preview的DotNetOpenAuth示例.
我可以从我的测试页面成功调用我的Action,但由于一行代码而遇到了一个奇怪的问题:
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错误屏幕图像如下:
更新
我发现AsActionResult是问题的原因,可能是因为扩展方法与.Net 4.0不兼容.我可以从request.RedirectingResponse获取OutgoingWebResponse对象但是知道如何将它转换为ActionResult