0
protected void Button_Click(object sender, CommandEventArgs e)
        {
            Response.Redirect("EnterSession.aspx?session=" + e.CommandArgument.ToString());
        }

上面的代码将 session_id 作为查询字符串传递给 EnterSession.aspx

我有以下与 EnterSession.aspx 相关的 c# 代码

protected string _SessionName = null;
        public string SessionName;
        public string sessionId
        {
            get
            {
                if (null == _SessionName)
                {
                    SqlConnection thisConnection = new SqlConnection(@"data Source=sorce");
                    {
                        thisConnection.Open();
                        SqlCommand thisCommand = thisConnection.CreateCommand();
                        thisCommand.CommandText = " SELECT session_name FROM myapp_Session WHERE session_id = @SessionId;";
                        {
                            thisCommand.Parameters.AddWithValue("sessionId", sessionId);
                            SqlDataReader thisReader = thisCommand.ExecuteReader();

                            thisCommand.Parameters["@SessionId"].Value = Convert.ToInt32(Request.QueryString["session"]);

                            using (var reader = thisCommand.ExecuteReader())
                            {
                                if (reader.Read())
                                {
                                    _SessionName = reader.GetString(0);
                                }
                                else
                                {
                                    throw new ArgumentException("Invalid session id");
                                }
                            }
                        }
                    }
                }
                return _SessionName;
            }
        }

现在在 EnterSession.aspx 中,我使用此代码将 session_name 传递给 GA

_gaq.push(['pageTrackerTime._trackEvent', document.getElementById('session_name').value, 'test', document.location.href, roundleaveSiteEnd]);

我也将此代码包含在 EnterSession.aspx 页面中

 <input type="hidden" id="session_name" />
<script type="text/javascript">
    document.getElementById('session_name').value = '<%= this.SessionName %>';
</script>

现在我找不到传递给 GA 服务器的 session_name。

有人可以告诉我我在哪里犯了错误..thanx

4

0 回答 0