使用 Firefox 时会话变量丢失,但在 IE 中有效
我在 HttpHandler 中设置 Session 变量,然后在 ASPX 页面的 Page_load 事件中获取其值。我正在使用它进行设置
public void ProcessRequest(HttpContext context)
{
HttpPostedFile file = context.Request.Files["Filedata"];
context.Session["WorkingImage"] = file.FileName;
}
(在有人建议我检查 file.FileName 的有效性之前,如果我在其中硬编码测试字符串,也会出现同样的问题。)它在 IE 中工作得很好,但在 Firefox 中,会话变量未找到,在以下代码中出现“对象引用未设置为对象的实例”错误:
protected void Page_Load(object sender, EventArgs e)
{
string loc = Session["WorkingImage"].ToString();
}
有人遇到过这个问题 - 并希望想出一种传递会话变量的方法吗?
I am setting a Session variable in an HttpHandler, and then getting its value in the Page_load event of an ASPX page. I'm setting it using
public void ProcessRequest(HttpContext context)
{
HttpPostedFile file = context.Request.Files["Filedata"];
context.Session["WorkingImage"] = file.FileName;
}
(And before someone suggests that I check the validity of file.FileName, this same problem occurs if I hard-code a test string in there.) It's working just fine in IE, but in Firefox the Session Variable is not found, getting the "Object reference not set to an instance of an object" error in the following code:
protected void Page_Load(object sender, EventArgs e)
{
string loc = Session["WorkingImage"].ToString();
}
Has anyone encountered this problem - and hopefully come up with a means for passing the session variable?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是针对 HTTPHandler 的吗?如果这偶然与 Flash 有关,并且 Flash 正在发出请求,您将会非常有兴趣阅读有关 Flash Cookie 错误。基本上,Flash 仅转发 IE cookie。
最简单的修复方法是在 Global.asax 中的 Application_BeginRequest 处调用 CorrectCookie,并将 SessionId 放入 Flash 请求的查询字符串中。
This is for an HTTPHandler? If this by some chance has something to do with Flash, and Flash is making the request, you will be very interested in reading about the Flash Cookie Bug. Basically, Flash only forwards IE cookies.
The easist fix is to call correctCookie at Application_BeginRequest in your Global.asax and put the SessionId in the querystring of the Flash request.