Home Blog .NET Request format is unrecognized for URL unexpectedly ending in /myMethodName
Request format is unrecognized for URL unexpectedly ending in /myMethodName
.NET
Written by Dicky   
Monday, 11 July 2011 10:46
AddThis Social Bookmark Button

I build an AJAX auto-complete that utilizes JSON and AJAX call. It works fine on my local machine using Windows Server 2003 and IIS 6, however, when I push it to staging server on Windows 2008 R2 and IIS 7.5 it's giving me this error: Request format is unrecognized for URL unexpectedly ending in /myMethodName.

I Google the error and all pointing to add this to your web.config:

 <system.web>
  <webServices>
    <protocols>
      <add name="HttpPost" />
      <add name="HttpSoap" />
    </protocols>
  </webServices>
</system.web>

However, it still not solve the issue. Using Fiddler and analyze the post and response traffic, it gives me another error information: Request format is invalid: application/json;

Then, I found out that I also need to add these 2 entries in my web.config.

<system.webServer>
  <handlers>
    <add name="ScriptHandlerFactory" verb="*" path="*.asmx" preCondition="integratedMode" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=4.0.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=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
  </handlers>
</system.webServer>

All is good now and the auto-complete works as expected!