页面处理之间的会话变量值的变化不知何故 [英] Session variable value changes between page processing somehow

查看:200
本文介绍了页面处理之间的会话变量值的变化不知何故的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个处理一个搜索查询的脚本。结果与排序头返回,所以点击批次#列标题,将受到很多#ASC结果进行排序。然而,如果你已经整理它ASC(此存储在一个会话变量),它会改变它的很多#DESC排序(并更新会话变量)。

所有这些工作完全,只要缩略图不包括在搜索结果中。当我做它们包括(其​​全部的作用是改变所述搜索查询,以包括所述图像的路径,然后输出用于图像列中的图像),则所有中断。这里是发生了什么:

在页面加载后,我的Response.Write(会话[排序])来看看我是如何排序(ASC或DESC)。

如果单击列标题,我检查,看看是否新的ORDER BY一栏已经列(也存储在一个会话变量按订单,会话[排序依据] )。

如果它不是previously设置为可变的顺序,它集排序会话变量ASC和会话变量设置为列名。

如果它是previously设置为可变的命令,它会检查当前的排序会话变量等于什么。如果它等于ASC,然后设置排序会话变量为desc和会话变量的顺序保持不变。如果它等于DESC,它集排序会话变量ASC和变量的顺序是一样的。

这部分实际上仍然工程。问题是,在处理页面的最后,我再次的Response.Write(会话[排序])来看看有什么变量被设置为。这是在页面加载到屏幕之前发生的最后的事情。所以请记住,当这种情况发生的页面被击中是它打印出的那种会话变量的第一件事,它确实是最后的事情再次打印出变量。

所以,当图像中包含的页面,点击一列将导致它要么排序ASC或DESC(取决于哪一列我点击,因为它似乎与每一个,其它列交替)。因此,可以说,我点击列首先引起的Response.Write(会话[sorty])是空白(因为它没有设置),第二打印ASC。当我再次单击列,第一次将打印DESC(这应该是ASC因为绝对没有什么是最后一个印刷和第一个印刷之间变化),第二个再打印ASC。

所以不知何故,会话变量被页面加载的变化时,有最后的印刷和第一次印刷之间绝对没有页面处理。 (以及每隔一个柱,它的逆转,显示出了在每一次底部顶部ASC和DESC)。同样,这个工程完全没有图像。

下面是唯一code。与缩略图包括脚本吧:

 如果(会话[incThumb]!= NULL)
    {
        resultText + =<表样式= \\宽度:100%; \\> \\ n< TR风格= \\FONT-重量:大胆;文本对齐:左; \\> \\ n百分位风格= \\下边框:1px的固体#000; \\>拇指< /第i \\ n百分位风格= \\下边框:1px的固体#000; \\><风格= \\字体 - 重量:大胆的;字体颜色:#000000; \\的href = \\searchResults.aspx页=+网页+&放大器; ORDERBY = tblItem.item_id \\>项目编号:LT; / A>< /第i \\ n百分位风格= \\下边框:1px的固体#000; \\><风格= \\FONT-重量:大胆的;字体颜色:#000000; \\的href = \\searchResults.aspx页=+网页+&放大器; ORDERBY = ITEM_TITLE \\>标题< / A>< /第i \\ n百分位风格= \\ 下边框:1px的固体#000; \\><风格= \\FONT-重量:大胆的;字体颜色:#000000; \\的href = \\searchResults.aspx页=+网页+&放大器; ORDERBY = tblItem.item_lot \\>批号:LT; / A>< /第i \\ n百分位风格= \\下边框:1px的固体#000; \\><风格= \\FONT-重量:大胆的;字体颜色:#000000; \\的href = \\searchResults.aspx页=+网页+&放大器; ORDERBY = tblItem.item_cs_txt_id \\>发货人ID< / A>< /第i \\ n百分位风格= \\下边框:1px的固体#000; \\><风格= \\FONT-重量:大胆的;字体颜色:#000000; \\的href = \\searchResults.aspx页=+网页+&放大器; ORDERBY = tblMcat.mcat_name \\>主类别< / A>< /第i \\ n百分位风格= \\下边框:1px的固体#000; \\><风格= \\FONT-重量:大胆的;字体颜色:#000000; \\的href = \\searchResults.aspx页=+网页+&放大器; ORDERBY = tblCat.cat_name \\>分类< / A>< /第i \\ n百分位风格= \\下边框:1px的固体#000; \\><风格= \\FONT-重量:大胆的;字体颜色:#000000; \\的href = \\searchResults.aspx页=+网页+&放大器; ORDERBY = tblItem.item_est_lo \\>低预估< / A>< /第i \\ n&LT? ;日式的= \\下边框:1px的固体#000; \\><风格= \\FONT-重量:大胆的;字体颜色:#000000; \\的href = \\searchResults.aspx页=+网页+&放大器; ORDERBY = tblItem.item_est_hi \\>高预估< / A>< /第i \\ n&LT ;日式的= \\下边框:1px的固体#000; \\><风格= \\FONT-重量:大胆的;字体颜色:#000000; \\的href = \\searchResults.aspx页=+网页+&放大器; ORDERBY = tblItem.item_reserve \\>储备< / A>< /第i \\ n百分位风格= \\下边框:1px的固体#000; \\><风格= \\FONT-重量:大胆的;字体颜色:#000000; \\的href = \\searchResults.aspx页=+网页+&放大器; ORDERBY = tblItem.item_status \\>状态< / A>< /第i \\ n百分位风格= \\下边框:1px的固体#000; \\><风格= \\FONT-重量:大胆的;字体颜色:#000000; \\的href = \\searchResults.aspx页=+网页+&放大器; ORDERBY = tblItem.item_pr \\>成交价< / A>< /第i \\ n百分位风格= \\下边框:1px的固体#000; \\><风格= \\FONT-重量:大胆的;字体颜色:#000000; \\的href = \\searchResults.aspx页=+网页+&放大器; ORDERBY = tblMailList.mail_ID \\>投标人ID< / A>< /第i \\ n< / TR> \\ N的;
    }
    其他
    {
        resultText + =<表样式= \\宽度:100%; \\> \\ n< TR风格= \\FONT-重量:大胆;文本对齐:左; \\> \\ n百分位风格= \\下边框:1px的固体#000; \\><风格= \\FONT-重量:大胆的;字体颜色:#000000; \\的href = \\searchResults.aspx页=+网页+&放大器; ORDERBY = tblItem.item_id \\>项目编号:LT; / A>< /第i \\ n百分位风格= \\下边框:1px的固体#000; \\><风格= \\FONT-重量:大胆的;字体颜色:#000000; \\的href = \\searchResults.aspx页=+网页+&放大器; ORDERBY = ITEM_TITLE \\>标题< / A>< /第i \\ n百分位风格= \\ 下边框:1px的固体#000; \\><风格= \\FONT-重量:大胆的;字体颜色:#000000; \\的href = \\searchResults.aspx页=+网页+&放大器; ORDERBY = tblItem.item_lot \\>批号:LT; / A>< /第i \\ n百分位风格= \\下边框:1px的固体#000; \\><风格= \\FONT-重量:大胆的;字体颜色:#000000; \\的href = \\searchResults.aspx页=+网页+&放大器; ORDERBY = tblItem.item_cs_txt_id \\>发货人ID< / A>< /第i \\ n百分位风格= \\下边框:1px的固体#000; \\><风格= \\FONT-重量:大胆的;字体颜色:#000000; \\的href = \\searchResults.aspx页=+网页+&放大器; ORDERBY = tblMcat.mcat_name \\>主类别< / A>< /第i \\ n百分位风格= \\下边框:1px的固体#000; \\><风格= \\FONT-重量:大胆的;字体颜色:#000000; \\的href = \\searchResults.aspx页=+网页+&放大器; ORDERBY = tblCat.cat_name \\>分类< / A>< /第i \\ n百分位风格= \\下边框:1px的固体#000; \\><风格= \\FONT-重量:大胆的;字体颜色:#000000; \\的href = \\searchResults.aspx页=+网页+&放大器; ORDERBY = tblItem.item_est_lo \\>低预估< / A>< /第i \\ n&LT? ;日式的= \\下边框:1px的固体#000; \\><风格= \\FONT-重量:大胆的;字体颜色:#000000; \\的href = \\searchResults.aspx页=+网页+&放大器; ORDERBY = tblItem.item_est_hi \\>高预估< / A>< /第i \\ n&LT ;日式的= \\下边框:1px的固体#000; \\><风格= \\FONT-重量:大胆的;字体颜色:#000000; \\的href = \\searchResults.aspx页=+网页+&放大器; ORDERBY = tblItem.item_reserve \\>储备< / A>< /第i \\ n百分位风格= \\下边框:1px的固体#000; \\><风格= \\FONT-重量:大胆的;字体颜色:#000000; \\的href = \\searchResults.aspx页=+网页+&放大器; ORDERBY = tblItem.item_status \\>状态< / A>< /第i \\ n百分位风格= \\下边框:1px的固体#000; \\><风格= \\FONT-重量:大胆的;字体颜色:#000000; \\的href = \\searchResults.aspx页=+网页+&放大器; ORDERBY = tblItem.item_pr \\>成交价< / A>< /第i \\ n百分位风格= \\下边框:1px的固体#000; \\><风格= \\FONT-重量:大胆的;字体颜色:#000000; \\的href = \\searchResults.aspx页=+网页+&放大器; ORDERBY = tblMailList.mail_ID \\>投标人ID< / A>< /第i \\ n< / TR> \\ N的;
    }

然后就低于这个,我也占了它打印出来的SQL的结果,这是(英文)的时候,如果包括缩略图会话变量不为空,包括缩略图多余的表格单元格,并添加图像

不用说,这其中有我难住了。我想AP preciate任何和所有响应/意见。让我知道如果你想看到了code。

修改

下面是回复于code:

 保护无效的Page_Load(对象发件人,EventArgs的发送)
{
    的Response.Write(会话[排序] +1< BR />中);
    字符串的OrderBy =;    base.SubNavItems.Add(搜索首页,searchHome.aspx);    如果(!的IsPostBack)
    {
    }    如果(!String.IsNullOrEmpty(的Request.QueryString [页]))
    {
        如果(!String.IsNullOrEmpty(的Request.QueryString [排序依据])){
            ORDERBY =的Request.QueryString [排序依据]的ToString()。
        }
        get_page(Int32.Parse(的Request.QueryString [页]的ToString()),排序依据。);
    }    如果(!String.IsNullOrEmpty(的Request.Form [ctl00 $ ContentPlaceHolder1 $拯救))
    {
        click_search();
    }    的Response.Write(会话[排序] +1< BR />中);
}

所以,因为页在列标题始终设置,当我排序列 get_page()方法被调用。 排序依据通过查询字符串设置,并沿该方法保护无效get_page(的Int32页面,字符串排序依据)通过这是包含以下code。在该方法的结尾也是的Response.Write(会话[排序] +2'; BR />中); 线,是过去的事情了方法执行。没有其他的方法在这一点上运行。另外,我刚打印出从.aspx页排序变量,得到了相同的结果作为最后的打印出的变量,该.aspx.cs页打印(其然后从第一个不同打印下一时间)。

我想我会继续和/排序逻辑添加到整个订单:

 如果(会话[排序依据]!= NULL)
    {
        如果(会话[排序依据]。的ToString()==排序依据)
        {
            如果(会话[排序]。的ToString()==ASC)
            {
                会话[排序] =DESC;
            }
            其他
            {
                会话[排序] =ASC;
            }
        }
        否则,如果(!String.IsNullOrEmpty(排序依据))
        {
            会话[排序] =ASC;
            会话[排序依据] =排序依据;
        }
    }
    否则,如果(!String.IsNullOrEmpty(排序依据))
    {
        会话[排序] =ASC;
        会话[排序依据] =排序依据;
    }
    其他
    {
        会话[排序] =ASC;
        会话[排序依据] =tblItem.item_id;
    }


解决方案

我要猜你在IE中遇到此。

此外,我要去猜测,这可能是因为是无效的图像来源,所以它的回发到根。我们曾经有过这个问题,以及,你永远不会抓到它,直到你看了喜欢的东西萤火网络流量提琴手。我们使用的应用程序真的只是退出,因为在存在的code的的Page_Load

切实发生了什么事情发生的是当图像URL失败,ASP.NET会在页面的根接收到的请求,因此回来后和消灭的信息。

此外,遵循@peer建议。

I have a script that processes a search query. The results are returned with a sortable header, so clicking on the Lot # column title would sort the results by the lot # ASC. However, if you had already sorted it ASC (which this is stored in a session variable), it will change it to sort it by the lot # DESC (and update that session variable).

All of this works perfectly, so long as thumbnails are not included in the search results. When I do include them (which all that does is change the search query to include the image path, then output an image for the image column), it all breaks. Here is what happens:

When the page loads, I response.write(Session["sort"]) to see how I am sorting (ASC or DESC).

If a column header is clicked, I check to see if the new "order by" column was already the "order by" column (also stored in a session variable, Session["orderby"]).

If it was not previously set as the order by variable, it sets the sort session variable to ASC and sets the order by session variable to the column name.

If it was previously set as the order by variable, it checks to see what the current sort session variable equals. If it equals ASC, then it sets the sort session variable to DESC and the order by session variable stays the same. If it equals DESC, it sets the sort session variable to ASC and the order by variable remains the same.

This part actually still works to. The problem is that at the end of processing the page, I again response.write(Session["sort"]) to see what the variable has been set to. This is the very last thing that happens before the page loads to the screen. So remember, the very first thing that happens when the page is hit is it prints out the sort session variable, and the very last thing it does is prints out the variable again.

So, when images are included in the page, clicking one column will cause it to sort either ASC or DESC (depending on which column I click on, as it seems to alternate with every-other column). So lets say the column I clicked caused the first response.write(Session["sorty"]) to be blank (since it's not set yet), and the second to print ASC. When I click the column again, the first will print DESC (which should be ASC since absolutely nothing is changed between the last one printed and the first one printed), and the second again prints ASC.

So somehow, the session variable is being changed between page loads when there is absolutely no page processing between the last print and the first print. (And on every-other column, it's reversed, showing up ASC at the top, and DESC at the bottom every single time.) Again, this works perfectly without the images.

Here's the only code with the thumbnail include script in it:

    if (Session["incThumb"] != null)
    {
        resultText += "<table style=\"width:100%;\">\n<tr style=\"font-weight:bold;text-align:left;\">\n<th style=\"border-bottom:1px solid #000;\">Thumb</th>\n<th style=\"border-bottom:1px solid #000;\"><a style=\"font-weight:bold; font-color:#000000;\" href=\"searchResults.aspx?page=" + page + "&orderBy=tblItem.item_id\">Item ID</a></th>\n<th style=\"border-bottom:1px solid #000;\"><a style=\"font-weight:bold; font-color:#000000;\" href=\"searchResults.aspx?page=" + page + "&orderBy=item_title\">Title</a></th>\n<th style=\"border-bottom:1px solid #000;\"><a style=\"font-weight:bold; font-color:#000000;\" href=\"searchResults.aspx?page=" + page + "&orderBy=tblItem.item_lot\">Lot</a></th>\n<th style=\"border-bottom:1px solid #000;\"><a style=\"font-weight:bold; font-color:#000000;\" href=\"searchResults.aspx?page=" + page + "&orderBy=tblItem.item_cs_txt_id\">Consignor ID</a></th>\n<th style=\"border-bottom:1px solid #000;\"><a style=\"font-weight:bold; font-color:#000000;\" href=\"searchResults.aspx?page=" + page + "&orderBy=tblMcat.mcat_name\">Master Category</a></th>\n<th style=\"border-bottom:1px solid #000;\"><a style=\"font-weight:bold; font-color:#000000;\" href=\"searchResults.aspx?page=" + page + "&orderBy=tblCat.cat_name\">Category</a></th>\n<th style=\"border-bottom:1px solid #000;\"><a style=\"font-weight:bold; font-color:#000000;\" href=\"searchResults.aspx?page=" + page + "&orderBy=tblItem.item_est_lo\">Low Est.</a></th>\n<th style=\"border-bottom:1px solid #000;\"><a style=\"font-weight:bold; font-color:#000000;\" href=\"searchResults.aspx?page=" + page + "&orderBy=tblItem.item_est_hi\">High Est.</a></th>\n<th style=\"border-bottom:1px solid #000;\"><a style=\"font-weight:bold; font-color:#000000;\" href=\"searchResults.aspx?page=" + page + "&orderBy=tblItem.item_reserve\">Reserve</a></th>\n<th style=\"border-bottom:1px solid #000;\"><a style=\"font-weight:bold; font-color:#000000;\" href=\"searchResults.aspx?page=" + page + "&orderBy=tblItem.item_status\">Status</a></th>\n<th style=\"border-bottom:1px solid #000;\"><a style=\"font-weight:bold; font-color:#000000;\" href=\"searchResults.aspx?page=" + page + "&orderBy=tblItem.item_pr\">Hammer Price</a></th>\n<th style=\"border-bottom:1px solid #000;\"><a style=\"font-weight:bold; font-color:#000000;\" href=\"searchResults.aspx?page=" + page + "&orderBy=tblMailList.mail_ID\">Bidder ID</a></th>\n</tr>\n";
    }
    else
    {
        resultText += "<table style=\"width:100%;\">\n<tr style=\"font-weight:bold;text-align:left;\">\n<th style=\"border-bottom:1px solid #000;\"><a style=\"font-weight:bold; font-color:#000000;\" href=\"searchResults.aspx?page=" + page + "&orderBy=tblItem.item_id\">Item ID</a></th>\n<th style=\"border-bottom:1px solid #000;\"><a style=\"font-weight:bold; font-color:#000000;\" href=\"searchResults.aspx?page=" + page + "&orderBy=item_title\">Title</a></th>\n<th style=\"border-bottom:1px solid #000;\"><a style=\"font-weight:bold; font-color:#000000;\" href=\"searchResults.aspx?page=" + page + "&orderBy=tblItem.item_lot\">Lot</a></th>\n<th style=\"border-bottom:1px solid #000;\"><a style=\"font-weight:bold; font-color:#000000;\" href=\"searchResults.aspx?page=" + page + "&orderBy=tblItem.item_cs_txt_id\">Consignor ID</a></th>\n<th style=\"border-bottom:1px solid #000;\"><a style=\"font-weight:bold; font-color:#000000;\" href=\"searchResults.aspx?page=" + page + "&orderBy=tblMcat.mcat_name\">Master Category</a></th>\n<th style=\"border-bottom:1px solid #000;\"><a style=\"font-weight:bold; font-color:#000000;\" href=\"searchResults.aspx?page=" + page + "&orderBy=tblCat.cat_name\">Category</a></th>\n<th style=\"border-bottom:1px solid #000;\"><a style=\"font-weight:bold; font-color:#000000;\" href=\"searchResults.aspx?page=" + page + "&orderBy=tblItem.item_est_lo\">Low Est.</a></th>\n<th style=\"border-bottom:1px solid #000;\"><a style=\"font-weight:bold; font-color:#000000;\" href=\"searchResults.aspx?page=" + page + "&orderBy=tblItem.item_est_hi\">High Est.</a></th>\n<th style=\"border-bottom:1px solid #000;\"><a style=\"font-weight:bold; font-color:#000000;\" href=\"searchResults.aspx?page=" + page + "&orderBy=tblItem.item_reserve\">Reserve</a></th>\n<th style=\"border-bottom:1px solid #000;\"><a style=\"font-weight:bold; font-color:#000000;\" href=\"searchResults.aspx?page=" + page + "&orderBy=tblItem.item_status\">Status</a></th>\n<th style=\"border-bottom:1px solid #000;\"><a style=\"font-weight:bold; font-color:#000000;\" href=\"searchResults.aspx?page=" + page + "&orderBy=tblItem.item_pr\">Hammer Price</a></th>\n<th style=\"border-bottom:1px solid #000;\"><a style=\"font-weight:bold; font-color:#000000;\" href=\"searchResults.aspx?page=" + page + "&orderBy=tblMailList.mail_ID\">Bidder ID</a></th>\n</tr>\n";
    }

Then just below this, I also account for it when printing out the SQL results, which is (in English), if the session variable for including thumbnails is not null, include the extra table cell for thumbnails and add in the image.

Needless to say, this one has me stumped. I would appreciate any and all responses/comments. Let me know if you want to see anymore code.

EDIT

Here's the response.write code:

protected void Page_Load(object sender, EventArgs e)
{
    Response.Write(Session["sort"] + " 1<br/>");
    string orderBy = "";

    base.SubNavItems.Add("Search Home", "searchHome.aspx");

    if (!IsPostBack)
    {
    }

    if (!String.IsNullOrEmpty(Request.QueryString["page"]))
    {
        if (!String.IsNullOrEmpty(Request.QueryString["orderBy"])){
            orderBy = Request.QueryString["orderBy"].ToString();
        }
        get_page(Int32.Parse(Request.QueryString["page"].ToString()), orderBy);
    }

    if (!String.IsNullOrEmpty(Request.Form["ctl00$ContentPlaceHolder1$save"]))
    {
        click_search();
    }

    Response.Write(Session["sort"] + " 1<br/>");
}

So because page is always set in the column headers, the get_page() method is called when I sort a column. orderBy is set through the query string and passed along to the method protected void get_page(Int32 page, String orderBy) which is what contains the below code. At the end of that method is also a Response.Write(Session["sort"] + " 2<br/>"); line which is the last thing that method does. No other method runs at this point. Also, I just printed out the sort variable from the .aspx page and got the same result as the last print out of the variable that the .aspx.cs page prints (which is then different from the first one printed the next time).

I figure I'll go ahead and add the logic to the whole order by/sort:

    if (Session["orderBy"] != null)
    {
        if (Session["orderBy"].ToString() == orderBy)
        {
            if (Session["sort"].ToString() == "ASC")
            {
                Session["sort"] = "DESC";
            }
            else
            {
                Session["sort"] = "ASC";
            }
        }
        else if (!String.IsNullOrEmpty(orderBy))
        {
            Session["sort"] = "ASC";
            Session["orderBy"] = orderBy;
        }
    }
    else if (!String.IsNullOrEmpty(orderBy))
    {
        Session["sort"] = "ASC";
        Session["orderBy"] = orderBy;
    }
    else
    {
        Session["sort"] = "ASC";
        Session["orderBy"] = "tblItem.item_id";
    }

解决方案

I'm going to guess you're experiencing this in IE.

Further, I'm going to guess that it's likely that there is an image source that is invalid and so it's posting back to the root. We used to have this problem as well, and you never caught it until you watched the network traffic with something like FireBug or Fiddler. Our application used to literally just logout because of the code that existed in the Page_Load.

Effectively what's going to happen is when an image URL fails, ASP.NET is going to receive a request at the root of the page and thus post back and wipe out the information.

Also, follow @peer advice.

这篇关于页面处理之间的会话变量值的变化不知何故的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆