ActionResult redirect renders using ToString()

2019-05-11 21:40发布

Using the following sample: http://www.west-wind.com/Weblog/posts/899303.aspx

The following line...

return req.RedirectingResponse.AsActionResult();

renders the string "DotNetOpenAuth.Messaging.OutgoingWebResponseActionResult". This is the class being returned as ActionResult in the line as posted. Does anyone know why I get the class name as string instead of a actual redirect?

Thnx in advance!

2条回答
放我归山
2楼-- · 2019-05-11 22:09

Could it be that you have multiple versions of MVC in your Bin directory and your web server? It strikes me that if you had multiple assemblies (different versions) of the MVC types like ActionResult loaded into your AppDomain, and the AsActionResult method returned one version and your MVC web app used a different version, that it might just bail out with a ToString. What version of ASP.NET MVC are you running? DotNetOpenAuth's AsActionResult method was compiled against the 1.0 RTM version of the MVC framework. If you're using ASP.NET MVC 2 (included with .NET 4.0), I could see this maybe being a problem.

I believe if you add this snippet to your MVC 2's web.config file, that it will allow you to use the official build of DotNetOpenAuth so you don't have to build your own:

<runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
        <dependentAssembly>
            <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
            <bindingRedirect oldVersion="1.0.0.0" newVersion="2.0.0.0" />
        </dependentAssembly>
    </assemblyBinding>
</runtime>
查看更多
等我变得足够好
3楼-- · 2019-05-11 22:14

Another solution, working for me with .Net 3.5 and MVC 2.

Instead of

var authRequest = relyingParty.CreateRequest(....);
....
return authRequest.RedirectingResponse.AsActionResult();

use

var authRequest = relyingParty.CreateRequest(....);
....
authRequest.RedirectToProvider();
Response.End();
return new EmptyResult();
查看更多
登录 后发表回答