为什么没有重定向到查看ASP.NET MVC 4 [英] Why did not redirect to view in ASP.NET MVC 4

查看:205
本文介绍了为什么没有重定向到查看ASP.NET MVC 4的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所有的,我有救了发布文件(请查看下面code)控制器。它花了大约20-30分钟来完成它。但我发现在保存文件后,RedirectToAction没有工作。显示的IE状态栏:

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.

顺便说一句,我的会话状态存储在SQL Server中。而超时时间为300分钟,我不知道这个问题是否与IIS 7应用程序池空闲时间的关系,我发布<一个href="http://stackoverflow.com/questions/12995345/iis-7-application-pool-work-process-life-and-session-life">here之前。 虽然它没有重定向到动作,我发现会话仍然存在。 文件和记录已成功保存。只有问题是它没有重定向。 请帮我.thanks。

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.

更新:

Web.config文件的httpRuntime设置是:

Web.config httpRuntime setting is:

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

编辑补充Index操作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));
    }

编辑补充提琴手跟踪信息

result protocol Host                 Url          

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

我可以看到在提琴手的响应HTML内容 /封装/指​​数,但浏览器只是冻结在同一页( /包上/上传)。

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

我不知道是否有一种方法来改变与JS code中的windows.location.href,我的想法是,当成功完成上传操作。然后输出到客户端像古典asp.net页面的Response.Write脚本一些脚本。 js的变化windows.location.href重定向到 /封装/指​​数。有没有什么办法让它在ASP.NET MVC4?

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?

推荐答案

使用内容(sResultScript,text / html的)来输出的JavaScript重定向索引网址。 IE8显示失败的页面,Chrome和Firefox就可以了。

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

这篇关于为什么没有重定向到查看ASP.NET MVC 4的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆