当我尝试使用会话从通用处理程序(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);
}
}