3

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!

promontis
  • 155
  • 1
  • 11
  • What is the return type in your function? – No Refunds No Returns Dec 21 '09 at 22:57
  • ActionResult... please see the sample in the url... the function is [AcceptVerbs(HttpVerbs.Post | HttpVerbs.Get), ValidateInput(false)] public ActionResult OpenIdLogOn(string returnUrl) {...} – promontis Dec 21 '09 at 23:03
  • IMO there is nothing wrong with the code sample as provided in the link, nor is the DotNetOpenAuth lib. I've checked the code several times and there isn't a lot of code which could be wrong. I think the *error* is somewhere in routing or web.config... the question is where exactly. – promontis Dec 21 '09 at 23:26

2 Answers2

4

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>
Andrew Arnott
  • 80,040
  • 26
  • 132
  • 171
  • This could be the case indeed! Will try it asap! – promontis Dec 22 '09 at 17:39
  • I've changed the reference to MVC 2. Initially, I got an exception saying that the signing was invalid, so I removed it. I now get the following error (which seems a lot better then the previous result): Must use the rewriter when using Contract.Requires at ContractHelper.TriggerFailureImplementation(ContractFailureKind kind, String displayMessage, String userMessage, String conditionText, Exception innerException) at ContractHelper.TriggerFailure(ContractFailureKind kind, String displayMessage, String userMessage, String conditionText, Exception innerException) ... – promontis Dec 23 '09 at 00:31
  • This error is because of the following: http://social.msdn.microsoft.com/Forums/en/codecontracts/thread/8f2a5842-7e18-42bf-b550-a30eb4c52817 So, basically, DotNetOpenAuth can't target MVC 2? – promontis Dec 23 '09 at 19:13
  • So you were targeting MVC 2. MVC 1 ought to automatically retarget to MVC 2. But the presence of any MVC 1 assemblies might break that. Can you make sure you don't have any MVC 1 assemblies lying around in your web site's Bin folder? – Andrew Arnott Dec 23 '09 at 23:32
  • 1
    DNOA can target MVC 2 no problem. But you have to have Code Contracts installed when you build DNOA -- otherwise you won't get a build break but the runtime won't work for the reason you gave. It's not MVC2, it's that Code Contracts must run ccrewrite on the generated assembly. – Andrew Arnott Dec 23 '09 at 23:33
  • To conclude this SO question: Andrew was spot on with the MVC version. I've recompiled his source targetting MVC2 and using the latest install of code contracts. Keep in mind to replace the MVC1 library assemblies in his lib with MVC2, because it seems code contracts will still use those instead of MVC2 (even if it is set correctly in your solution). Kudos to Andrew! – promontis Dec 24 '09 at 10:32
  • I can confirm that DNOA works with MVC2 without a rebuild with the web.config piece. But if you want to compile against the Mvc Source it won't compile. – MvcCmsJon Feb 17 '10 at 17:42
  • Could be there another reason for this message? I'm using the prebuild DNOA v3.4.3, .NET 3.5 SP1 with MVC2 and VS2010. Before I upgraded the project to VS2010, I hadn't this problem. – EricSch Apr 23 '10 at 20:23
  • EricSch, you haven't mentioned making the web.config change. Did you do that? – Andrew Arnott Apr 24 '10 at 21:21
1

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();
Palani
  • 8,962
  • 11
  • 53
  • 62