以下方法在Windows Server 2008 R2中正常运行,我的应用已注册。但是当我在实时服务器2012 R2上部署它时。然后在response.redirect之后我的会话变空了。请帮助我...因为我找到几天的解决方案,但没有找到任何东西。 我已经使用了response.redirect over load方法,但使用的更少。我比较了两台服务器的IIS设置(2008 r2和2012)但没有进展。请帮帮我。
public ActionResult Index_Post(string txtMsg)
{
var fb = new FacebookClient();
var loginUrl = fb.GetLoginUrl(new
{
client_id = ConfigurationManager.AppSettings["facebook:AppId"],
redirect_uri = ConfigurationManager.AppSettings["facebook:url"],
response_type = "code",
scope = "email,publish_actions,publish_stream,manage_pages,read_insights,read_stream" // Add other permissions as needed
});
TempData["messages"] = txtMsg;
Response.Redirect(loginUrl.AbsoluteUri);
return View();
}
public static string RefreshTokenAndPostToFacebook(string currentAccessToken, string heading, string Url = "", string description = "")
{
string newAccessToken = RefreshAccessToken(currentAccessToken);
PostToFacebook(newAccessToken, heading, Url, description);
return newAccessToken; // replace current access token with this
}
public static string RefreshAccessToken(string currentAccessToken)
{
FacebookClient fbClient = new FacebookClient();
Dictionary<string, object> fbParams = new Dictionary<string, object>();
fbParams["client_id"] = ConfigurationManager.AppSettings["facebook:AppId"];
fbParams["grant_type"] = "fb_exchange_token";
fbParams["client_secret"] = ConfigurationManager.AppSettings["facebook:AppSecret"];
fbParams["fb_exchange_token"] = currentAccessToken;
JsonObject publishedResponse = fbClient.Get("/oauth/access_token", fbParams) as JsonObject;
return publishedResponse["access_token"].ToString();
}
public static void PostToFacebook(string pageAccessToken, string heading, string Url = "", string description = "")
{
FacebookClient fbClient = new FacebookClient(pageAccessToken);
fbClient.AppId = ConfigurationManager.AppSettings["facebook:AppId"];
fbClient.AppSecret = ConfigurationManager.AppSettings["facebook:AppSecret"];
Dictionary<string, object> fbParams = new Dictionary<string, object>();
fbParams["message"] = heading + System.Environment.NewLine + System.Environment.NewLine + Url;
var pageid = "/me/feed";
var publishedResponse = fbClient.Post(pageid, fbParams);
}
public ActionResult FaceBookData()
{
if (Request.QueryString["code"] != null)
{
string accessCode = Request.QueryString["code"].ToString();
var fb = new FacebookClient();
// throws OAuthException
dynamic result = fb.Post("oauth/access_token", new
{
client_id = ConfigurationManager.AppSettings["facebook:AppId"],
client_secret = ConfigurationManager.AppSettings["facebook:AppSecret"],
redirect_uri = ConfigurationManager.AppSettings["facebook:url"],
code = accessCode
});
var accessToken = result.access_token;
try
{
RefreshTokenAndPostToFacebook(accessToken, TempData["messages"].ToString(),
"");
return RedirectToAction("PlayerMyLocker", "Player", new { share = "1" });
}
catch (Exception ex)
{
return RedirectToAction("PlayerMyLocker", "Player", new { share = ex });
}
}
else
{
return RedirectToAction("AcademyDescription","Academy",new{id=0});
}
}