【问题标题】:Response Redirection Failed to work响应重定向失败
【发布时间】:2014-05-19 03:38:18
【问题描述】:

我想将 FB 响应从客户端传递到服务器端(代码隐藏)

 function testAPI() {
            console.log('Welcome!  Fetching your information.... ');
            FB.api('/me', function (response) {

                $.post('http://localhost:4741/Default.aspx',
                { fbid: response.id, firstname: response.first_name, lastname: response.last_name, email: response.email, bday: response.birthday }, 
                function (result) {

                });
                 console.log('Good to see you, ' + response.id + response.name + response.id + response.email + response.gender + response.birthday + '.');

            });
        }

我想获取页面加载中的值和过程

protected void Page_Load(object sender, EventArgs e)
        {

            var fbid = Request.Form["fbid"];
            var fname = Request.Form["firstname"];
            var lname = Request.Form["lastname"];
            var email = Request.Form["email"];
            var bday = Request.Form["bday"];
            if (!Page.IsPostBack)
            {
                if (fbid != null)
                {

                    if (CheckFBLogin(fbid.ToString()) == true)
                    {
                        Response.Redirect("Users.aspx");
                    }

                    else
                    {
                        Response.Redirect("Register.aspx");
                    }
                }
            }



        }

CheckFBLogin(fbid.ToString()) 是位于页面后面相同代码中的函数。但是当通过 Response.Redirect("Register.aspx",true);没有任何事情发生。它将保留在同一页面中。

应该解决什么问题?

【问题讨论】:

  • 所以如果 CheckFBLogin 成功,你重定向到 Register.aspx,如果失败 - 你做同样的事情吗?这里有错字吗?
  • 好的,我认为有错字,但是 response.redirect 都不起作用

标签: c# jquery asp.net redirect post


【解决方案1】:

您将“endResponse”参数中的“true”传递给 Response.Redirect。这将导致当前请求结束,从而导致 ThreadAbortException。如果您不处理此问题,或者您只是通过吞下异常来处理它,您的重定向将显示为“不起作用”。建议传递“false”。

【讨论】:

  • 你好,我尝试删除并更改为 false。是的,页面仍未重定向。是不是 myjquery 代码错误?
  • 我不这么认为,因为那不是你要重定向的地方,你只是在做一个 http 帖子。您可以在 pageLoad 上设置断点并单步执行吗?它甚至击中了 Response.Redirects 吗?您可以检查事件日志是否有您未处理的任何异常吗?
  • 是的,它通过响应重定向行。但它会回忆起网站主人而不是移动到页面
  • 好的,你可以在浏览器中打开调试器,转到网络选项卡,看看你得到了什么响应代码吗?
  • 是的,我调试它们并在注册页面上点击断点。但仍在 deafult.apx 中
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2010-12-02
  • 1970-01-01
  • 2016-10-06
  • 2012-12-27
  • 2020-06-30
  • 1970-01-01
相关资源
最近更新 更多