Currently the web methods or most of the methods in classic asp .net serializes using system.web.script.serialization.javascriptserializer class and this returns the javascript object's datetime members with values such as
"/Date(number of ticks)/"
. I understand this is an infamous problem and most people suggest using some kind of converters after we receive the data or return the data as string instead of objects.
For example the class
public class Person
{
public String Name { get; set; }
public int Age { get; set; }
public DateTime DOB { get; set; }
}
if returned via a System.Web.Services.WebMethod with a [ScriptMethod(ResponseFormat = ResponseFormat.Json)] decoration, the response will be returned as below in result.d
{Name:"Steve", Age:30, DOB:"/Date(1249335477787)/"};
And we need to apply some code to convert the DOB into ISO format or some other acceptable format.
But I am just trying to see if some one has done some kind of response tweaking or using an over-ridden class to return the DateTime values from web methods. Is there a way to over-ride the javascriptserializer's functionality and use it in asp .net web methods so that it returns the date directly in ISO format? I am aware that it can be done in asp .net MVC in a few ways.
Is the same can be done in asp .net web form's web methods? That would save a lot of code and bugs as well :)