This seems impossible but I will ask anyway.
Here is the scenario
I have a MVC 3 View that loads 3 partial views, one for login, one for registration, and one for OpenID logins.
The first 2 work great with Ajax, however; the third view uses ajax to post to my openid controller where I go do some DotNetOpenAuth magic
Example:
var response = authenticationRequest.RedirectingResponse;
if(response.Status == HttpStatusCode.Redirect)
{
return Json(new {redirectUrl=response.Headers[HttpResponseHeader.Location] });
}
I am doing a redirect from the returned Json from the controller the OpenId Login form posts to, “remember this post is via ajax”. So after the redirect I would like to replace the contents of the div with the initial openid login partial view with a new view based on what happens after the redirect to the provider, the user signs in, and I get a response back in my actionMethod. For instance, I will check in my database to see if I already have an account for that open id. If I don’t I would like to present a partial view to the user with some basic questions etc.. and let them add the open id account.
So it seems that this is not possible since the redirect kills any chance of getting data back to the original page.
Any ideas?
Process bullets as requested:
- Main View renders a partial view with a form
- Form inside partial view does ajax post to an ActionMethod in a controller
- ActionMethod in the controller returns Json with a redirectUrl
- OnSuccess callback function reads json result and does a client side redirect to the redirectUrl
- User logs in to openid provider at redirected location
- OpenId provider sends results back to the same ActionMethod that generated the initial Json redirectUrl result
- Perform DB lookup on open Id and return partial view if user not found or log user in if found.
I would like to have the view id the user is not found get loaded in the original div the login form was in. This doesn’t work.
A full page redirect destroys the original page, so no, you can’t have a subsequent redirect bring the user back to the original page with only one
<DIV>updated.You have at least two alternatives:
Simply take the full page redirect, and when the authentication result comes back from the Provider your MVC controller re-renders the entire original page. Downside: the controller can’t restore any user-specific state from the other views that were previously there.
Use a popup window to log the user in, and when the login has completed the popup closes itself, passing back the authentication data to the parent page which can then re-render whatever portion it wants.
DotNetOpenAuth supports both approaches, but of course there is plenty of code in the controller and view, external to the library, that you have to write. I do have a sample that demonstrates a relatively polished #2 implementation. It was at http://openidux.dotnetopenauth.net/ but the site appears to be down right now. But you can see a screenshot and download a project template for it here: http://visualstudiogallery.msdn.microsoft.com/81153747-70d7-477b-b85a-0374e7edabef