search envelope-o feed check
Home Unanswered Active Tags New Question
user comment-o

The request must start with 'JSON' string.

Asked by André
7 years ago.

I working on a web application written in ASP.NET MVC 5 with Razor.
When i publish website in IIS it throws the error "The request must start with JSON string".

Someone who can help me?

My View:
@Html.DayPilotScheduler("dp", new DayPilotSchedulerConfig
{
//BackendUrl = Url.Action("Backend", "Scheduler"),
BackendUrl = @Url.Action("Backend", "Scheduler"),
//Url.Content("~/Scheduler/Backend"),
StartDate = new DateTime(DateTime.Today.Year, 1, 1),
Days = 365,
Scale = TimeScale.Day,
CellGroupBy = GroupBy.Month,
CellDuration = 1440,

TimeRangeSelectedHandling = TimeRangeSelectedHandlingType.JavaScript,
TimeRangeSelectedJavaScript = "create(start, end, resource);",
TimeRangeSelectingJavaScript = "selecting(args)",

EventClickHandling = EventClickHandlingType.JavaScript,
EventDeleteHandling = EventDeleteHandlingType.CallBack,
EventMoveHandling = EventMoveHandlingType.CallBack,

...
})

Controller:

[HandleError]
public class SchedulerController : Controller
{
BDCalendarEntities dc = new BDCalendarEntities();

public ActionResult Backend()
{
return new Scheduler().CallBack(this); <-- THE PROBLEM
}

class Scheduler : DayPilotScheduler
{
BDCalendarEntities dc = new BDCalendarEntities();
protected override void OnInit(InitArgs e)
{
Timeline = new TimeCellCollection();
LoadEmployeesAndHolidays();
ScrollTo(DateTime.Today.AddDays(-1));
Separators.Add(DateTime.Now, Color.Red);

}
...

mvc
Comment posted by Dan Letecky [DayPilot]
7 years ago.

Can you check the request body using browser developer tools? The AJAX requests generated by the client-side Scheduler object start with "JSON" string.

If you call the backend url using a request that doesn't start with "JSON" you'll see an error like this. This can also happen if you open the backend URL directly in the browser.

Comment posted by André
7 years ago.

The request Payload start with JSON

My request payload:

JSON{"action":"Init","type":"CallBack","header":{"v":"1595","control":"dps","id":"dp","startDate":"2017-01-01T00:00:00","days":365,"cellDuration":1440,"cellGroupBy":"Month","cellWidth":50,"cellWidthSpec":"Fixed","viewType":"Resources","hourNameBackColor":"#ECE9D8","showNonBusiness":true,"businessBeginsHour":9,"businessEndsHour":18,"weekStarts":0,"treeEnabled":false,"backColor":"#FFFFD5","nonBusinessBackColor":"#FFF4BC","locale":"pt-pt","timeHeaders":[{"groupBy":"Month","format":null},{"groupBy":"Day","format":null}],"cssOnly":true,"cssClassPrefix":"scheduler_default","durationBarMode":"Duration","showBaseTimeHeader":true,"rowHeaderColumns":[{"width":80,"title":"room"}],"rowMarginBottom":0,"rowMarginTop":0,"rowMinHeight":50,"scale":"Day","clientState":{},"scrollX":0,"scrollY":0,"selected":[],"selectedRows":[],"rangeStart":"2017-01-01T00:00:00","rangeEnd":"2017-01-01T00:00:00","resources":[],"dynamicLoading":false,"separators":[],"tree":[]}}

Comment posted by Dan Letecky [DayPilot]
7 years ago.

It is possible that your IIS server uses a custom handler that processes the request InputStream. This moves the position in the stream to the end.

If that's the case you need to disabled the handler for this request or move the InputStream read position back to the start after reading it.

Comment posted by André
7 years ago.

Thanks Dan, but i don't Know how to solve this! My program is based on https://code.daypilot.org/32389/asp-net-mvc-hotel-room-booking which has the same problem, I checked the forum, and are more people with this problem "The request must start with JSON string". Does anyone know how to solve it?

Comment posted by Dan Letecky [DayPilot]
7 years ago.

You need to check your IIS configuration. It looks like it is configured to intercept the request (maybe some kind of authentication module - see also https://docs.microsoft.com/en-us/iis/configuration/system.webserver/modules/). This module reads the InputStream and moves the InputStream.Position. This makes the HTTP request body unavailable to the DayPilotScheduler.CallBack() method.

I recommend checking the IIS and web application configuration to see what intercepts the request.

You can also try to reset the InputStream position before calling CallBack in the Backend() method:

if (HttpContext.Current.Request.InputStream.CanSeek)
{
  HttpContext.Current.Request.InputStream.Seek(0, System.IO.SeekOrigin.Begin);
}
This question is more than 1 months old and has been closed. Please create a new question if you have anything to add.