2

I am working on a ASP.NET MVC application. There are partial views, a controller, handler and a model that is iterated and its items are displayed on view. It works fine, until I get more than 25 elements in my list. If I return 26 elements it starts showing a "The connection was reset" message in the browsers(FF and Chrome):

enter image description here

These are the partial views:

Iterating model items:

@foreach(ingredientsListItemModel ingredientsListItem in Model.ingredientsListItems)
    {
        <text>
            <div id="@ingredientsListItem.ContainerDiv">
                @Html.Partial("Partial/ingredientsListItem", ingredientsListItem)
            </div>    
        </text>
    }

Showing each item as a container:

@using (Ajax.BuildForm("AddElement", "Item", Model.FormId, new AjaxOptions { UpdateTargetId = Model.ContainerDiv }))
{
    <div id="ingredientsListitem" class="yui3-g ingredientsListitem">
        <div class="yui3-u-1-3">
            <a href="@url">
                <img src="@Model.ImageUrl" alt="" />
            </a>
        </div>
        <div class="yui3-u-2-3">
            <div class="itemdescription">
                <a href="@url">
                    @MvcHtmlString.Create(Model.ItemDescription)
                </a>
            </div>
        </div>
    </div>
    @Html.HiddenFor(m => m.ingredientsListId);
}

These are the controller methods to have an idea of the data:

Controller:

public ActionResult GetingredientsList()
        {
            if (Request.IsAjaxRequest())
            {
                return PartialView("Partial/ingredientsList", Handler.GetingredientsListModel(MvcApplication.ClientApplication));
            }

Handler:

  private static IEnumerable<ingredientsListItemModel> GetingredientsListItems(ClientApplication clientApplication)
        {
//Some code...
            return list.ToList();
//if this list contains more than 25 elements it starts failing and showing the Connection reset error.
        }

I tried changing the web.config to include (but it didn't work):

<configuration> 
   <system.web.extensions>
       <scripting>
           <webServices>
               <jsonSerialization maxJsonLength="50000000"/>
           </webServices>
       </scripting>
   </system.web.extensions>
</configuration> 

No matter which element is in the list, it can be any data but once it is bigger than 25 items, it fails. I am thinking there could be a response size limit to be changed in some way? in IIS? in web.config? It seems it is a size limit problem. Well, any help will be very appreciated.

Alberto Montellano
  • 5,886
  • 7
  • 37
  • 53
  • 1
    There are also settings for `maxRequestLength` and `maxAllowedContentLength` that may be involved: https://stackoverflow.com/questions/23327338/maxrequestlength-for-net-4-5-1-framework – David Tansey Jan 07 '21 at 22:22
  • @DavidTansey this is about controller response size it seems, not about request size. – Alberto Montellano Jan 08 '21 at 13:24
  • How is the controller called? There is the if ajax request there (and no else clause?), Is it ajax called then? If it is, there could be an error at the client that creates a wrong uri. Also, is it possible the list contains nulls? – Wiktor Zychla Jan 10 '21 at 16:29
  • Please place the complete code for `GetingredientsList` controller action. We can't reproduce the problem. – Amirhossein Mehrvarzi Jan 10 '21 at 21:22
  • @WiktorZychla it is ASP MVC, the code is displaying how the model is sent to the Partial View, and then the model is iterated in razor. The data is correct, I tried with different sets of correct data items , it fails only when it contains more than 25 items of size. – Alberto Montellano Jan 11 '21 at 12:38
  • @AmirhosseinMehrvarzi it only returns a list of items, it works perfectly with 25-26 items, once it gets more it starts failing. That's why I am supposing it could be a size limit problem with razor, web.config, IIS?... – Alberto Montellano Jan 11 '21 at 12:40
  • I guess you should reproduce your issue in a smallest possible app and just publish it on github for someone to look into. Without the complete code, the issue is not reproducible. – Wiktor Zychla Jan 11 '21 at 13:20
  • Which environment is this running in? IIS? Self-hosted console app? Azure AppService? Check for the status of the Windows or Linux process which you run this in - it might be crashing. Also, either connect a debugger or iteratively add logging messages until you pinpoint the spot closest to crash. – Roman Polunin Jan 14 '21 at 22:18
  • 2
    just a suggestion are you sure that the 26th or what is after it of elements is consistence in its data. My only thoughts is if, the 26th unlucky has some null values, or any other problem that breaks the system with out you getting any information about it. – Maytham Fahmi Jan 16 '21 at 14:02
  • 2
    Try to enable Failed-Request Tracing in IIS. See instructions here: https://learn.microsoft.com/en-us/iis/troubleshoot/using-failed-request-tracing/troubleshooting-failed-requests-using-tracing-in-iis. Trace "all contents" and after that copy/paste the log file. – Diego B Jan 17 '21 at 07:48
  • @maytham-ɯɐɥʇʎɐɯ yes , I verified the 26th element, it is a valid item. It is a list with the same elements, if I remove the position 25 for example, the 26th will be included and all will be fine. It seems a problem with the size of the response. – Alberto Montellano Jan 17 '21 at 18:35

0 Answers0