我有这个控制器
[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 });
}
这里我要做的基本上是,如果我的访问令牌已过期,则重定向到Facebook OAuth
但代码Redirect(redirectUrl);
根本不会触发。我的问题是
答案 0 :(得分:1)
我认为它是因为[HttpPost]属性。您可以将您的网址传递给客户端,并调用navigate()或window.location = myurl。
答案 1 :(得分:1)
您需要返回重定向ActionResult
:
return Redirect(redirectUrl);