1

I have client code running in javascript which tries to send html content to a custom handler.

The client side code looks like this:

   ...
    $('#txt_content').val($(div).html());
        performClick($('#submit_excel_form'));

And the handler code is:

public void ProcessRequest(HttpContext context)
        {
            string name = context.Request["txt_name"];
            string content = context.Request["txt_content"];
           ...
        }

The problem is that when using Chrome browser, the message the handler get (txt_content) is not complete. Maximum length of string I get is: 524288

When I run in explorer , I get the full message (with length=567130).

I saw a similar quesion here, but it was not answered (The solution with setting maxAllowedContentLength doesn't work).

Would appreciate any help. Thanks, Omer

Edit:

This is the relevant part from the configuration file:

<webServices>
      <protocols>
        <add name="HttpGet"/>
        <add name="HttpPost"/>
      </protocols>
    </webServices>
    <customErrors mode="Off" defaultRedirect="Default.aspx">
      <error statusCode="500" redirect="Default.aspx"/>
      <error statusCode="404" redirect="404.aspx"/>
    </customErrors>
    <globalization culture="he-IL" uiCulture="he-IL" resourceProviderFactoryType="BusinessLogic.Culture.CultureProviderFactory" enableClientBasedCulture="false"/>
    <compilation debug="true">
      <assemblies>
        <add assembly="System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
        <add assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
        <add assembly="System.Data.DataSetExtensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
        <add assembly="System.Xml.Linq, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
        <add assembly="System.Messaging, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
      </assemblies>
    </compilation>
    <httpRuntime requestValidationMode="2.0" maxRequestLength="2097151" requestLengthDiskThreshold="8192000"/>
    <authentication mode="Forms"/>
    <pages clientIDMode="Static" validateRequest="false">
      <controls>
        <add tagPrefix="amr" namespace="BusinessLogic.Controls" assembly="BusinessLogic"/>
        <add tagPrefix="asp" namespace="System.Web.UI" assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
        <add tagPrefix="asp" namespace="System.Web.UI.WebControls" assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
      </controls>
      <namespaces>
        <add namespace="Infrastructure"/>
        <add namespace="CommonData"/>
      </namespaces>
    </pages>
    <httpHandlers>
      <remove verb="*" path="*.asmx"/>
      <add verb="*" path="*.asmx" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
      <add verb="*" path="*_AppService.axd" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
      <add verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" validate="false"/>
    </httpHandlers>
    <httpModules>
      <add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
    </httpModules>
  </system.web>
  <system.codedom>
    <compilers>
      <compiler language="c#;cs;csharp" extension=".cs" warningLevel="4" type="Microsoft.CSharp.CSharpCodeProvider, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
        <providerOption name="CompilerVersion" value="v3.5"/>
        <providerOption name="WarnAsError" value="false"/>
      </compiler>
      <compiler language="vb;vbs;visualbasic;vbscript" extension=".vb" warningLevel="4" type="Microsoft.VisualBasic.VBCodeProvider, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
        <providerOption name="CompilerVersion" value="v3.5"/>
        <providerOption name="OptionInfer" value="true"/>
        <providerOption name="WarnAsError" value="false"/>
      </compiler>
    </compilers>
  </system.codedom>
  <system.webServer>
    <security>
      <requestFiltering>
        <requestLimits maxAllowedContentLength="2147483648" />
      </requestFiltering>
    </security>
    <validation validateIntegratedModeConfiguration="false"/>
    <modules>
      <remove name="ScriptModule"/>
      <add name="ScriptModule" preCondition="managedHandler" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
    </modules>
    <handlers>
      <remove name="WebServiceHandlerFactory-Integrated"/>
      <remove name="ScriptHandlerFactory"/>
      <remove name="ScriptHandlerFactoryAppServices"/>
      <remove name="ScriptResource"/>
      <add name="ScriptHandlerFactory" verb="*" path="*.asmx" preCondition="integratedMode" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
      <add name="ScriptHandlerFactoryAppServices" verb="*" path="*_AppService.axd" preCondition="integratedMode" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
      <add name="ScriptResource" preCondition="integratedMode" verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
    </handlers>
  </system.webServer>
3
  • I'm not seeing the reason for it either. Perhaps add further information about your configuration, and show the form you're submitting. Commented Aug 8, 2013 at 8:39
  • Thanks , I've added the config sections, the html is created dynamically, I'm not sure if it will be useful to add it here. Commented Aug 8, 2013 at 11:02
  • What version of .net are you on? Commented Aug 9, 2013 at 15:50

1 Answer 1

1

You can likely get around this limit/bug with a multipart post.

A full, but complicated, example of doing exactly this in a .ashx can be found at: How to post data from a webform page to an HTTPHandler.ashx file? This injects a file uploader that then multipart posts the "File" data into the handler. Messy.

You may be able to do this more straightforwardly, by combining the multipart xhr.send from XMLHttpRequest POST multipart/form-data with a method similar to the first part of the answer possibly using BinaryReader b = new BinaryReader(FileUpload1.PostedFile.InputStream);

or

   //read content into a buffer
   request.Content.LoadIntoBufferAsync().Wait();

   request.Content.ReadAsStringAsync().ContinueWith(t =>
   {
       apiRequest.Content = t.Result;
       _repo.Add(apiRequest);
   });

from Multipart form POST using ASP.Net Web API

or even potentially the .NET 4.5 async from how to read multi part form data in .net web api controller

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, I can have a more simple workaround, and build the excel itself in the server side, same way as the client does it to display the table to the user. What I was curious about is why does Chrome has this limitation?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.