Asp.net 会话变量在响应后丢失。从facebook重定向

Asp.net 会话变量在响应后丢失。从facebook重定向,asp.net,asp.net-mvc,facebook,session-variables,windows-server-2012,Asp.net,Asp.net Mvc,Facebook,Session Variables,Windows Server 2012,以下方法在Windows server 2008 R2中运行良好,我的应用已注册。但当我在live server 2012 R2上部署它时。然后在response.redirect之后,我的会话变为空。请帮帮我。。因为我在几天内找到了解决办法,但没有找到任何东西。 我也使用了response.redirect重载方法,但使用较少。我比较了两台服务器(2008 r2和2012)的IIS设置,但没有任何进展。请帮帮我 public ActionResult Index_Post(string t

以下方法在Windows server 2008 R2中运行良好,我的应用已注册。但当我在live server 2012 R2上部署它时。然后在response.redirect之后,我的会话变为空。请帮帮我。。因为我在几天内找到了解决办法,但没有找到任何东西。 我也使用了response.redirect重载方法,但使用较少。我比较了两台服务器(2008 r2和2012)的IIS设置,但没有任何进展。请帮帮我

  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});
        }
    }
public ActionResult Index_Post(字符串txtMsg)
{
var fb=新FacebookClient();
var loginUrl=fb.GetLoginUrl(新
{
client_id=ConfigurationManager.AppSettings[“facebook:AppId”],
重定向_uri=ConfigurationManager.AppSettings[“facebook:url”],
响应类型=“代码”,
scope=“电子邮件、发布操作、发布流、管理页面、阅读洞察、阅读流”//根据需要添加其他权限
});
TempData[“messages”]=txtMsg;
重定向(loginUrl.AbsoluteUri);
返回视图();
}
公共静态字符串RefreshTokenAndPostToFacebook(字符串currentAccessToken,字符串标题,字符串Url=,字符串描述=)
{
字符串newAccessToken=RefreshAccessToken(currentAccessToken);
PostToFacebook(newAccessToken、标题、Url、描述);
return newAccessToken;//将当前访问令牌替换为
}
公共静态字符串RefreshAccessToken(字符串currentAccessToken)
{
FacebookClient fbClient=新建FacebookClient();
Dictionary fbParams=新字典();
fbParams[“客户端id”]=ConfigurationManager.AppSettings[“facebook:AppId”];
fbParams[“授予类型”]=“fb交换令牌”;
fbParams[“client_secret”]=ConfigurationManager.AppSettings[“facebook:AppSecret”];
fbParams[“fb_交换_令牌”]=currentAccessToken;
JsonObject publishedResponse=fbClient.Get(“/oauth/access_token”,fbParams)作为JsonObject;
返回publishedResponse[“access_token”].ToString();
}
公共静态无效PostToFacebook(字符串pageAccessToken,字符串标题,字符串Url=,字符串描述=)
{
FacebookClient fbClient=新的FacebookClient(pageAccessToken);
fbClient.AppId=ConfigurationManager.AppSettings[“facebook:AppId”];
fbClient.AppSecret=ConfigurationManager.AppSettings[“facebook:AppSecret”];
Dictionary fbParams=新字典();
fbParams[“message”]=标题+System.Environment.NewLine+System.Environment.NewLine+Url;
var pageid=“/me/feed”;
var publishedResponse=fbClient.Post(pageid,fbParams);
}
公共操作结果FaceBookData()
{
if(Request.QueryString[“code”!=null)
{
string accessCode=Request.QueryString[“code”].ToString();
var fb=新FacebookClient();
//抛出异常
动态结果=fb.Post(“oauth/access_令牌”,新
{
client_id=ConfigurationManager.AppSettings[“facebook:AppId”],
client_secret=ConfigurationManager.AppSettings[“facebook:AppSecret”],
重定向_uri=ConfigurationManager.AppSettings[“facebook:url”],
代码=访问代码
});
var accessToken=result.access\u token;
尝试
{
RefreshTokenAndPostToFacebook(accessToken,TempData[“messages”]。ToString(),
"");
返回重定向操作(“PlayerMyLocker”,“Player”,new{share=“1”});
}
捕获(例外情况除外)
{
返回重定向操作(“PlayerMyLocker”,“Player”,new{share=ex});
}
}
其他的
{
返回重定向操作(“AcademyDescription”,“Academy”,新的{id=0});
}
}

google将server.transfer和reposne.redirect区别开来,以便更好地理解..server.transfer用于同一台服务器。我猜,但根据你的建议,我已经实施并测试了它,但问题并没有解决