【发布时间】:2012-12-26 10:56:04
【问题描述】:
我正在一个网站上工作,用户可以在其中上传文件/照片,并且为了上传,我正在使用 uploadify 控件 我正在将登录的用户 ID 和当前日期和年份添加到文件中,然后保存它,我已将用户 ID 保存在 Session(Session [“userid”])中,它在 IE 和 chrome 上工作正常,但是当我从 firefox 运行它时,它显示 Session["userid"]= null ,因此它没有上传文件,下面是我上传文件的代码
public string UploadFile(HttpPostedFileBase fileData)
{
try
{
if (fileData != null && fileData.ContentLength > 0)
{
var root = AppDomain.CurrentDomain.BaseDirectory + @"Uploads\File\";
var filname = fileData.FileName.Split('.')[0] + "_" + Session["userid"].ToString() + "_" + DateTime.Now.Day + DateTime.Now.Year + "." + fileData.FileName.Split('.')[1];
var path = root + Path.GetFileName(filname);
//if (System.IO.File.Exists(path))
// return "Upload Failed! A file with this name already exists.";
fileData.SaveAs(path);
return "1";
}
return "file not selected.";
}
catch (Exception ex)
{
throw ex;
}
}
虽然用户已登录,但仍显示会话为空
【问题讨论】:
标签: c# asp.net-mvc file-upload uploadify