将(Asp.Net)会话变量(由uploadify上传)从webmethod传递到同一页面?
当我尝试使用会话从通用处理程序(upload.ashx)获取上传的文件名时,没问题。我还可以在同一页面上使用 webmethod,并且 uploadify 效果很好,但 Session["fileName"] 变得为空。我的代码有什么问题吗?我只需要使用通用处理程序来获取文件名吗?
[WebMethod(EnableSession = true)]
public void LoadPicture(HttpContext context)
{
try
{
HttpPostedFile file = context.Request.Files["Filedata"];
context.Session["fileName"] = file.FileName;
............一些调整大小和保存图像代码............
context.Response.Write("1");
}
catch (Exception ex)
{
context.Response.Write("0");
}
}
protected void Button1_Click(object sender, EventArgs e)
{
using (_modelService = new ModelService())
{
ModelEntity _models = new ModelEntity();
......some codes....
_models.modelphoto = Session["fileName"].ToString();
_modelService.ModelAdd(_models);
}
}
When i try to get uploaded filename from generic handler (upload.ashx) using session its ok, no problem. I can also use webmethod on samepage and uploadify works great, but Session["fileName"] is getting null. Is there anything wrong on my code? Do i only need to use generic handler to get filename?
[WebMethod(EnableSession = true)]
public void LoadPicture(HttpContext context)
{
try
{
HttpPostedFile file = context.Request.Files["Filedata"];
context.Session["fileName"] = file.FileName;
....................Some resize and save image codes.........
context.Response.Write("1");
}
catch (Exception ex)
{
context.Response.Write("0");
}
}
protected void Button1_Click(object sender, EventArgs e)
{
using (_modelService = new ModelService())
{
ModelEntity _models = new ModelEntity();
......some codes....
_models.modelphoto = Session["fileName"].ToString();
_modelService.ModelAdd(_models);
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
上传使用 Flash。 Flash 不发送 cookie。在 ASP.NET 中,会话是通过 cookie 进行跟踪的。所以,抱歉,没有与 uploadify 进行会话。
Uploadify uses Flash. Flash doesn't send cookies. In ASP.NET sessions are tracked by cookies. So, no session with uploadify, sorry.