0

I have hosted an ASP.NET Web App in Azure App service. The function of web app is to read the data from CSV file and while (csv.ReadNextRecord()) holds true, mandatory columns data are used to send user invitation using invitation endpoint[HTTP POST Method] and optional columns data are used to patch the data to the user, post successful invitation[HTTP PATCH Method]. The app runs good locally but when deployed it won't run past 3:59 mins. and throws an Error as shown below:

enter image description here

Sample Code

/// <summary>
/// Post method for importing users 
/// </summary>
/// <param name="postedFile"></param>
[HttpPost]
public async Task<ActionResult> ImportAsync(IFormFile postedFile)
{
    if (postedFile != null)
    {
        try
        {
            if (!Directory.Exists(path))
            {
                //Some Code Here...
            }

            //Validate uploaded file and return error.
            if (fileExtension != ".csv")
            {
                //Some Code Here...
            }
            //Copy the contents of uploaded file
            //with the same filename as uploaded file
            //under the "wwwroot/Uploads" directory
            using (Stream fileStream = new FileStream(file, FileMode.Create))
            {
                //Some Code Here...
            }
            // open the CSV file which is a CSV file with headers
            using (StreamReader reader = new StreamReader(file))
            using (CsvReader csv = new CsvReader(reader, true))
            {
                //Some Code Here...
                for (int i = 0; i < headers.Length; i++)
                {
                    //Some Code Here...
                }
                //Validation for mandatory columns
                if (!HeaderExists)
                {
                    //Some Code Here...
                }
                else
                {
                    while (csv.ReadNextRecord())
                    {
                        //Some Code Here...
                        #region Prepare user data with mandatory and optional attributes seperately
                        for (int i = 0; i < fieldCount; i++)
                        {
                            //Some Code Here...
                        }
                        #endregion

                        #region Invite User, Patch Optional User Data and Add User to Group
                        if (!string.IsNullOrWhiteSpace(InvitedUserEmailAddress))
                        {
                            bool isValidEmail = //Some Code Here...
                            if (isValidEmail)
                            {
                                //Some Code Here...
                                
                                var userInvitationStatus = //Some Code Here...
                                if (userInvitationStatus)
                                {
                                    //Some Code Here...
                                    #region Patch Optional User Data
                                    if (userDataToPatch.Count != 0)
                                    {
                                        //Some Code Here...
                                        var userPatchStatus = //Some Code Here...
                                        if (userPatchStatus)
                                        {
                                            //Some Code Here...
                                        }
                                    }
                                    else
                                    {
                                        //Some Code Here...
                                    }
                                    #endregion

                                    #region Add User to Group
                                    //Add user to group if there is some data provided in the optional groupObjectId column
                                    if (userGroupData.Count != 0)
                                    {
                                        foreach (string groupId in userGroupData[0].Split(","))
                                        {
                                            //Some Code Here...
                                            if (groupIdValid)
                                            {
                                                //Some Code Here...
                                                if (signedInUserGroupOwner)
                                                {
                                                    //Some Code Here...
                                                    if (!invitedUserGroupMember)
                                                    {
                                                        //Some Code Here...
                                                        if (addInvitedUserToGroupStatus)
                                                        {
                                                            //Some Code Here...
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                    #endregion
                                }
                            }
                        }
                        #endregion
                    }
                }
            }

            //Some Code Here...
        }
        catch (Exception ex)
        {
            //Some Code Here...
            return View();
        }
    }
    else
    {
        ViewBag.Message = "Please select the file first to upload.";
        return View();
    }
}

I have gone through various online sources, aware of the 4 min. TCP Keep-alive limit {SOURCE: https://stackoverflow.com/a/38676086/9275701} and also tried increasing the execution time limit in Web.Config file as shown below but NO luck.

<system.web>
    <customErrors mode="Off" />
    <httpRuntime executionTimeout="99999" />
</system.web>

Can any one please please please help here what I can do for this?

NOTE: The bulk requests is being sent via CSV and processing time can take up to hours. Currently, When I try locally for 50 users it takes approx. 12 mins. to process the entire user records.

Lucifer
  • 141
  • 12

1 Answers1

0
  • We need to add the maxRequestLength in web.config file
  • The parameter maxRequestLength indicates maximum file uploading size supported by the ASP. Net Application To increase the execution time limit in web.config add the below settings
 <system.web>
      <httpRuntime executionTimeout="300" maxRequestLength="2147483647" />
 </system.web>

Also, we need to add the maxAllowedContentLength under system.webServer tag.

<system.webServer>
    <security>
        <requestFiltering>
            <requestLimits maxAllowedContentLength="2147483648" />
        </requestFiltering>
    </security>
</system.webServer>

The Compilation debug has to be set tofalse My web.config enter image description here

Harshitha
  • 3,784
  • 2
  • 4
  • 9
  • Tried the solution but it didn't resolved the issue and still throws the same Request Timeout Error. :( – Lucifer Oct 07 '22 at 12:38