我正在将数据从Excel文件上传到数据库,MVC代码读取第一条记录,但是在第二条记录上,它是通过在“结果”处添加用户后通过Time Out异常完成的。
HttpPostedFileBase file = Request.Files["students"];
if ((file != null) && (file.ContentLength > 0) && !string.IsNullOrEmpty(file.FileName))
{
string fileName = file.FileName;
string fileContentType = file.ContentType;
byte[] fileBytes = new byte[file.ContentLength];
var data = file.InputStream.Read(fileBytes, 0, Convert.ToInt32(file.ContentLength));
}
var studentList = new List<RegisterViewModel>();
using (var package = new ExcelPackage(file.InputStream))
{
var currentSheet = package.Workbook.Worksheets;
var workSheet = currentSheet.First();
var noOfCol = workSheet.Dimension.End.Column;
var noOfRow = workSheet.Dimension.End.Row;
for (int rowIterator = 2; rowIterator <= noOfRow; rowIterator++)
{
var student = new RegisterViewModel();
var Fname = workSheet.Cells[rowIterator, 1].Value.ToString();
var Mname = workSheet.Cells[rowIterator, 2].Value.ToString();
var Lname = workSheet.Cells[rowIterator, 3].Value.ToString();
student.Name = Fname + " " + Mname + " " + Lname;
student.UserName = workSheet.Cells[rowIterator, 4].Value.ToString();
student.Email = workSheet.Cells[rowIterator, 5].Value.ToString();
student.Password = workSheet.Cells[rowIterator, 6].Value.ToString();
student.ConfirmPassword = workSheet.Cells[rowIterator, 7].Value.ToString();
ApplicationDbContext context = new ApplicationDbContext();
var user = new ApplicationUser { UserName = student.UserName, Email = student.Email, Name = student.Name };
var result = await UserManager.CreateAsync(user, student.Password);
if(result!="false")
{
答案 0 :(得分:0)
在executionTimeout
中设置httpRuntime tah的web.config
属性,如下所示:
<system.web>
...
<httpRuntime targetFramework="4.5.1" executionTimeout="30" />
</system.web>
希望这对您有帮助...