I reach my login page with the parameter "returnUrl" set to the URL I was on. Then, I login via OpenID (DotNetOpenAuth), and call FormsAuthentication.RedirectFromLoginPage()
. The login is successful, however I am not returned to the original page I was on.
I'm having the same problem on logout - when I log out I don't remain on the same page, even though the logout link contains the correct "returnUrl" parameter.
What am I doing wrong?
Here is the code snippet. I am returning EmptyResult() after the call to RedirectFromLoginPage, because I don't really know what to do (see this related question)
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");
}
// Stage 3: OpenID Provider sending assertion response
switch (response.Status)
{
case AuthenticationStatus.Authenticated:
var claimedIdentifier = response.ClaimedIdentifier;
var user = _userRepository.FindByOpenId(claimedIdentifier);
if (user != null)
{
// login
FormsAuthentication.RedirectFromLoginPage(user.Id.ToString(), false);
return new EmptyResult();
// TODO - http://stackoverflow.com/questions/1991710/understanding-redirections-in-asp-net-mvc
// throw new Exception("Should never get here");
}
...