This below methods are working fine in Windows server 2008 R2 and my app is registered. but when i deploy it on live server 2012 R2. Then after response.redirect my session went empty. Please help me.. because i am finding solution form couple of days but did not find any thing. i have used the response.redirect over load method also but use less. i have compare the IIS setting of both servers (2008 r2 and 2012) but no progress. Please help me out.
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});
}
}