codeandcloud
codeandcloud

Reputation: 55210

Redirect in HttpPost Controller not working

I have this controller

[HttpPost]
public ActionResult Compose(ComposeMessage composeMessage)
{
    var message = "";
    dynamic fbPost = new ExpandoObject();
    fbPost.message = composeMessage.Message;
    dynamic result = FBHelper.PostInFacebook(fbPost, associatedAccount.ProviderAccessToken);
    if (((IDictionary<String, object>)result).ContainsKey("error"))
    {
        Session["PostMessage"] = fbPost;
        var redirectUrl = FBHelper.GetLoginUrl("email,read_stream,publish_stream");
        //HttpContext.ClearError();
        //the below redirect does not work
        Redirect(redirectUrl);
        //message = "Posting to Facebook failed. \n";
    }
    else
    {
        message = "Posting to Facebook successful. \n";
    }
    return Json(new { success = message });
}

Here what I am trying to do basically is to Redirect to Facebook OAuth if my access token is expired.
But the code Redirect(redirectUrl); does not fire at all. My questions are

  1. What is wrong with the code?
  2. Why is redirect not firing?

Upvotes: 1

Views: 592

Answers (2)

Nick Butler
Nick Butler

Reputation: 24383

You need to return the redirect ActionResult:

return Redirect(redirectUrl);

Upvotes: 1

Sanja Melnichuk
Sanja Melnichuk

Reputation: 3505

I think its becouse [HttpPost] attribute. You can pass your url to client and the call navigate(), or window.location = myurl.

Upvotes: 1

Related Questions