简体   繁体   中英

c# MVC ContentResult is not returning to the View after performing Lengthy operation

in my MVC application, Controller returns a value but view never gets it and I get error as : "The Remote Host Closed Connection. The Error Code is xxxxxx"

public ActionResult FileUpload(string positionDate)
        {

               ReturnVal = "very Lenghty Operation , comes back in 1 hour"        
                return Content(ReturnVal);
            }
            catch (Exception ex)
            {
                //Console.WriteLine(ex.Message);
                _logger.InfoFormat("DataFileUpload failed with Message {0}", ex.Message);
                throw ex;
            }

        }

ReturnVal has the message I need.

function OnClick(s, e) {
    positionDate = ReportingPositionDate.GetDate().toDateString();
    //debugger;
    if (true) {
        $.ajax({
            type: "POST",
            url: "@Url.Action("FileUpload", "ImportData")",
            data: JSON.stringify({ positionDate: positionDate }),
            dataType: "text",
            contentType: "application/json; charset=utf-8",
            beforeSend: function () { lpImport.Show(); },
            success: function (msg)
            {
                ImportDataGridView.PerformCallback();
                ImportSuccessMessage.SetText(msg);
                lpImport.Hide();
            },
            Error: function (xhr) {
                alert(xhr)
                ImportDataGridView.PerformCallback();
            },
            timeout: 10000000
        })

Any idea how can I increase this timeout? My view gets value when the operation is completed within 60 minutes. It fails with "Remote Host Closed Connection" after that. web.config has

<httpRuntime targetFramework="4.5.1" maxRequestLength="2097151" executionTimeout="21600" />
<sessionState mode="InProc" cookieless="true" timeout="500" />

But it doesn't help.

Any idea how can I extend the timeout on this one ?
在此处输入图片说明

My view gets value when the operation is completed within 60 minutes.

You definitely do not want user to wait 60 minutes - not even a minute.

Ideally, you want to pass it to background scheduler, and return back to UI immediately . Then, let the background scheduler perform the task.

How to run Background Tasks in ASP.NET

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM