2016. 5. 25. 12:20

아래 코드를 입력하면 클래스 오브젝트를 XML 또는 JSON 타입으로 리턴시켜준다.

[Global.aspx]

public class Global : HttpApplication
{
    void Application_Start(object sender, EventArgs e)
    {
        // 응용 프로그램 시작 시 실행되는 코드
        AreaRegistration.RegisterAllAreas();
        GlobalConfiguration.Configure(WebApiConfig.Register);
        RouteConfig.RegisterRoutes(RouteTable.Routes);

        // Content-type 전역지정
        GlobalConfiguration.Configuration.Formatters.Clear();
        //GlobalConfiguration.Configuration.Formatters.Add(new System.Net.Http.Formatting.XmlMediaTypeFormatter());
        GlobalConfiguration.Configuration.Formatters.Add(new System.Net.Http.Formatting.JsonMediaTypeFormatter());
    }
}


Posted by CoolDragon