1

所有,我有一个保存发布文件的控制器(请查看下面的代码)。完成它大约需要20-30分钟。但我保存文件后发现,RedirectToAction 不起作用。显示的 IE 状态栏:

Waiting for http://......./index.

顺便说一句,我的会话状态存储在 SQL Server 中。超时时间为 300 分钟。我不确定这个问题是否与我之前在此处发布的 IIS 7 应用程序池空闲时间有关。虽然它没有重定向到操作,但我发现会话仍然存在。文件和记录已成功保存。唯一的问题是它没有重定向。请帮助我。谢谢。

[HttpPost]
[AcceptButton("Upload")]
public ActionResult Upload(UploadPackageModel model)
{
    //after about 20-30 min for 160MB file-upload, runs here.
    DeployLogModel tempLog = null;
    try
    {
        if (Request.Files.Count > 0 && Request.Files[0].ContentLength > 0)
        {
            var file = Request.Files[0];
            var fileName = Path.GetFileName(file.FileName);
            string sUploadFullPath = string.Empty;
            model.ID = Guid.NewGuid();//PK id of Uploaded Package
            string sUploadFileName = model.ID + Path.GetExtension(file.FileName);
            model.CreatedBy = DataHelp.LoginAdministrator.ID.ToString();
            model.LastUpdatedBy = DataHelp.LoginAdministrator.ID.ToString();
            model.PackageSize = Request.Files[0].ContentLength;
            model.CreatedDate = DateTime.UtcNow;
            model.LastUpdatedDate = DateTime.UtcNow;
            model.PackageName = fileName;

            string rootPath = AppDomain.CurrentDomain.BaseDirectory + "\\" + "DeployPackages\\";

            sUploadFullPath = Path.Combine(rootPath, sUploadFileName);
            model.PackagePath = sUploadFullPath;
            if (!Directory.Exists(rootPath))
                Directory.CreateDirectory(rootPath);

            file.SaveAs(sUploadFullPath);//Save the uploaded package.
            model.SavePackInfoIntoDB(model);//Save record to DB
        }
    }
    catch (Exception ex)
    {
        Log.Write("-Upload-Package-failed-:\r\n" + ex.Message + "\r\n" + ex.StackTrace);
    }
    return RedirectToAction("Index");//does not work.
}

文件和记录已成功保存。唯一的问题是它没有重定向。

更新:

Web.config httpRuntime 设置为:

<httpRuntime executionTimeout="14400" maxRequestLength="716800" />

编辑添加索引操作代码:

public ActionResult Index(int? page)
{
        var db = DbContextHelper.CreateInstance();

        //Find all uploaded packages.
        var packages = db.DeployPackages.OrderByDescending(x => x.CreatedDate).Select(x => new PackageModel
             {
                 PackageId = x.ID,
                 UploadedBy = x.CreatedBy,
                 Description = x.Description,
                 PackageName = x.PackageName,
                 PackageSize = x.PackageSize,
                 PackagePath = x.PackagePath,
                 UploadTime = x.CreatedDate,
                 VersionName = x.VersionName
             }).ToList();

        int pageSize = ConfigHelper.BigPageSizeNum;
        int pageNumber = (page ?? 1);
        return View(packages.ToPagedList(pageNumber, pageSize));
    }

编辑添加 Fiddler 跟踪信息

result protocol Host                 Url          

200    http     test.cloudapp.net    /package/upload
200    http     test.cloudapp.net    /package/index

我可以在 fiddler 中看到响应 html 内容/package/index,但浏览器只是冻结在同一页面(/package/upload)上。

我想知道是否有办法用js代码更改windows.location.href,我的想法是成功完成上传操作。然后向客户端输出一些脚本,例如经典 asp.net 页面中的 response.write 脚本。js 将 windows.location.href 更改为重定向到/package/index. 有没有办法在 ASP.NET MVC4 中实现它?

4

1 回答 1

0

用于输出 javascript以Content(sResultScript, "text/html")重定向索引 url。IE8 显示失败页面,chrome 和 Firefox 都可以。

于 2012-11-01T03:54:19.127 回答