Bug 6989 - Posting json data (with "Content-Type: application/json" in http header) to any aspx page will cause Exception
Summary: Posting json data (with "Content-Type: application/json" in http header) to a...
Status: NEW
Alias: None
Product: Class Libraries
Classification: Mono
Component: System.Web (show other bugs)
Version: 2.10.x
Hardware: PC Linux
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2012-09-07 10:30 UTC by xiewenbin
Modified: 2015-06-24 12:12 UTC (History)
4 users (show)

See Also:
Tags:
Is this bug a regression?: ---
Last known good build:


Attachments

Description xiewenbin 2012-09-07 10:30:57 UTC
Description of Problem:
make a http post request (with "Content-Type: application/json" in headers) to any web pages in an asp.net application will cause Exception.

Steps to reproduce the problem:
Input curl command in linux shell, like this:

curl -d '{}' -H "Content-Type: application/json" 127.0.0.1:8080/Default.aspx

the address "127.0.0.1:8080/Default.aspx" can be replaced with any valid aspx page url.

Actual Results:
Got a html page with error info:

Server Error in '/' Application Argument is out of range.

Parameter name: startIndex

Description: HTTP 500. Error processing request.
Stack Trace: 
System.ArgumentOutOfRangeException: Argument is out of range.
Parameter name: startIndex
  at System.String.Substring (Int32 startIndex)
  at System.Web.Script.Services.RestHandler..ctor (System.Web.HttpContext context, System.Type type, System.String filePath) 
  at System.Web.Script.Services.RestHandler.GetHandler (System.Web.HttpContext context, System.Type type, System.String filePath)
  at System.Web.Handlers.ScriptModule.PostAcquireRequestState (System.Object sender, System.EventArgs e)
  at System.Web.HttpApplication+<RunHooks>c__Iterator5.MoveNext ()
  at System.Web.HttpApplication+<Pipeline>c__Iterator6.MoveNext ()
  at System.Web.HttpApplication.Tick ()

Version information: 
Mono Runtime Version: 2.10.5 (Debian 2.10.5-1ubuntu0.1); 
ASP.NET Version: 4.0.30319.1

Expected Results:
the post request is parsed correctly and processed by the web page.

How often does this happen? 
Every time.

Additional Information:

My System: Ubuntu 11.10 64-bit + Apache2, Mono was installed with apt-get.

This problem doesn't occur in windows 7 + IIS environment.
Comment 1 mchavarriae 2012-11-05 15:21:21 UTC
Hi.

This error is happening to us. Someone helped you?
Comment 2 xiewenbin 2012-11-05 21:13:28 UTC
To avoid this error, I modified the code with "Content-Type: text/plain" in http header.
Comment 3 weisen 2013-02-01 11:59:54 UTC
Hi,

this Bug is still active. (version 2.10.8) 

https://github.com/mono/mono/blob/master/mcs/class/System.Web.Extensions/System.Web.Script.Services/RestHandler.cs 

/-> BAD CODE  LINE 98 
string methodName = request.PathInfo.Substring (1);
--< 


Please fix it.

Thx 

@xiewenbin@gmail.com  thx your solution works.
Comment 4 core 2015-06-24 11:56:00 UTC
Same error. Is this going to be fixed?
Comment 5 core 2015-06-24 11:56:25 UTC
[root@dev test]# mono --version
Mono JIT compiler version 4.0.1 (tarball Thu May 28 04:56:48 EDT 2015)
Copyright (C) 2002-2014 Novell, Inc, Xamarin Inc and Contributors. www.mono-project.com
        TLS:           __thread
        SIGSEGV:       altstack
        Notifications: epoll
        Architecture:  amd64
        Disabled:      none
        Misc:          softdebug
        LLVM:          supported, not enabled.
        GC:            sgen
Comment 6 core 2015-06-24 12:12:52 UTC
Registered content-type for JSON is "application/json", so provided workaround is only temporary solution which breaks standards.

Note You need to log in before you can comment on or make changes to this bug.