页面之间的ASP.Net会话数据丢失 [英] ASP.Net Session data lost between pages

查看:109
本文介绍了页面之间的ASP.Net会话数据丢失的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我今天在使用Web应用程序时遇到了奇怪的行为.当我从页面导航到另一页面时,我丢失了一个特定的会话变量数据.

I came across a weird behavior today w/ my web application. When I navigate from a page to another, I lose one particular session variable data.

我可以在firefox中启动该应用程序,并且可以看到会话数据没有丢失.

I'm able to launch the app in firefox and able to see that the session data is not lost.

我使用Response.Redirect(page2, false)重定向到另一个页面.

I use Response.Redirect(page2, false) to redirect to another page.

下面的代码用于跟踪会话变量

Below code was used to track session variables

System.IO.StreamWriter sw = new System.IO.StreamWriter(@"c:\test.txt", true);
for (int i = 0; i < Session.Count; i++)
{
 sw.WriteLine(Session.Keys[i] + " " + Session.Contents[i]);
}
sw.Close();

有人可以帮我吗?感谢您的帮助.

Can anyone help me in this? Any help is appreciated.

推荐答案

我遇到了完全相同的问题,就我而言,我找到了造成此问题的原因.事实证明,当我调用Response.Redirect()方法时,我使用的是完整网址,而不仅仅是页面名称.因此,当我在localhost/myapp/page1.aspx中时,我重定向到MYMACHINENAME/myapp/page2.aspx,这就是每个页面的会话都不同的原因.我仅使用"page2.aspx"在代码中更正了此问题,然后任何浏览器(IE,firefox)上的最终URL为localhost/myapp/page2.aspx.不知道您是否按照我的方式使用这些URL在这样做,但也许这个答案可以给你一个线索.谢谢,编码不错

I was having exactly the same problem and in my case I found the cause of this behavior. It turned out to be that when I was invoking the Response.Redirect() method I was using the full url instead of just the page name. So when I was in localhost/myapp/page1.aspx I redirected to MYMACHINENAME/myapp/page2.aspx and that's why the sessions were different for each page. I corrected this in my code using only "page2.aspx" and then the final url on any browser (IE, firefox) was localhost/myapp/page2.aspx.Don't know if you're playing with the urls the way I was doing it but maybe this answer can give you a clue. Thanks and good coding

这篇关于页面之间的ASP.Net会话数据丢失的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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