IAuthenticationRequest.RedirectToProvider is not supposed to return, yet it does

.net, asp.net, asp.net-mvc, dotnetopenauth, openid

Solution

Since you're using ASP.NET MVC, you should use this code:

using DotNetOpenAuth.Messaging; // required for the extension method to work

    return relyingParty.CreateRequest(openid).RedirectingResponse.AsActionResult();

Apparently ASP.NET usually throws an exception as a result of the `RedirectToProvider()` call, but not always. But the above code will work and is more MVC friendly.

Problem

The method `DotNetOpenAuth.OpenId.RelyingParty.IAuthenticationRequest.RedirectToProvider()` is documented never to return: Redirects the user agent to the provider for authentication. Execution of the current page terminates after this call. However, it does return under the latest implementation (3.4.3). I'm using the following code: ``` using (var relayingParty = new OpenIdRelyingParty()) { var response = relayingParty.GetResponse(); if (response == null) { // Stage 2: user submitting Identifier var openId = Request.Form["openId"]; relayingParty.CreateRequest(openId).RedirectToProvider(); throw new Exception("Never gets here"); } ... } ``` (The line with "Never gets here" is reached). I need to return an ActionResult from this method ... - Is this a known bug? - Is there a aorkaround? Should I return EmptyResult? As far as I understand this is a bug - I submitted it in the project issue tracker.

Original source