1

All, I have a controller which saved the posted file(Please review below code). It took about 20-30 min to finish it. But I found after saving the file, the RedirectToAction didn't work. the IE status bar shown :

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

BTW, My session state is stored in SQL Server. And timeout is 300 Mins. I am not sure this problem if has relationship with IIS 7 app pool idle time which I post here before. Although it didn't redirect to the action ,I found the session still exists. The file and the record were saved successfully .Only problem is It didn't redirect. please help me .thanks.

[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.
}

The file and the record were saved successfully .Only problem is It didn't redirect.

Update:

Web.config httpRuntime setting is:

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

Edited to add Index action code:

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));
    }

Edited to add Fiddler trace info

result protocol Host                 Url          

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

I can see the response html content in the fiddler for /package/index,but the browser just freeze on the same page(/package/upload) .

I wondered if there is a way to change the windows.location.href with js code ,My idea is when finished upload action successfully. then output to client some script like response.write script in classical asp.net page . the js change windows.location.href to redirect to /package/index. Is there any way to make it in ASP.NET MVC4?

Community
  • 1
  • 1
Joe.wang
  • 11,537
  • 25
  • 103
  • 180
  • Looks like there is a lot of logging -- what do your logs show? – McGarnagle Oct 21 '12 at 07:57
  • Sorry for this ,Please forget about those logs. I had updated code above, Thanks – Joe.wang Oct 21 '12 at 08:03
  • The file and the record were saved successfully .Only problem is it didn't redirect. – Joe.wang Oct 21 '12 at 08:05
  • The issue still exists even I had change the IIS 7 Application Pool Idle time out is 300. Seems the issue has nothing with this .Thanks. – Joe.wang Oct 21 '12 at 08:15
  • Maybe this will help: http://stackoverflow.com/questions/3829202/iis-request-timeout-on-long-asp-net-operation – McGarnagle Oct 21 '12 at 08:21
  • the current setting of `httpRuntime` element in web.config is ``. – Joe.wang Oct 21 '12 at 08:36
  • You mention that the `RedirectToAction` does not work but what happens? Does the browser freeze on the same page even if you have confirmed that the controller action has successfully finished executing? Can you reproduce this behavior in other browsers? – Darin Dimitrov Oct 21 '12 at 09:27
  • @DarinDimitrov Yes, the broswser freeze on the same page .But I can see the browser try to redirect to the url I specified in the `RedirectToAction` after successfully finished `upload` action, Because the status bar of IE8 shows `wait for http:\\..\index` , the `index` is specified in the `RedirectToAction` parameter.thanks – Joe.wang Oct 21 '12 at 09:37
  • What does the Index action do? What about the other browsers? – Darin Dimitrov Oct 21 '12 at 09:45
  • @DarinDimitrov I didn't test it with other browsers because of the CSS issue. I need effort to make it compatible with other browsers. sorry.I had updated it and added `index` action code. please review it .thanks. – Joe.wang Oct 21 '12 at 09:52
  • @DarinDimitrov I think I can trace the IE8 http message with tools like Fiddler to see what happen to the Browser . What do u think of this? thanks – Joe.wang Oct 21 '12 at 10:00
  • Yes, you could use Fiddler. But try with a different browser as well. – Darin Dimitrov Oct 21 '12 at 10:02
  • @DarinDimitrov I had updated to add trace info ,Please help to review it ,thanks. – Joe.wang Oct 21 '12 at 11:26
  • How are you calling the `Upload` action? Are you using AJAX or some client side upload component? – Darin Dimitrov Oct 22 '12 at 05:40
  • @DarinDimitrov Using `Html.BeginForm("Upload", "Package", FormMethod.Post, new { enctype = "multipart/form-data" })` thanks. – Joe.wang Oct 22 '12 at 06:05
  • @DarinDimitrov Now I am trying to use `Content(sResultScript, "text/html");` to output javascript to redirect `index` url. not finished yet. thanks – Joe.wang Oct 22 '12 at 06:08
  • @DarinDimitrov I am using `Content(sResultScript, "text/html")` to output javascript to redirect `index` url. and I test it with IE8 and Chrome, IE8 shown a failed page , chrome is ok . – Joe.wang Oct 22 '12 at 06:35

1 Answers1

0

Using Content(sResultScript, "text/html") to output javascript to redirect index url. IE8 shown a failed page , chrome and Firefox is OK .

Joe.wang
  • 11,537
  • 25
  • 103
  • 180