2016-04-22 19 views
5

Ich schreibe einen Webhook in asp.net Core Mvc, wo der Anrufer einige JSON Posts. Der Inhaltstyp ist jedoch auf application/vnd.myget.webhooks.v1+json festgelegt. Ich möchte nur diese Inhaltstypkarte zu JsonInputFormatter haben.Hinzufügen MediaType zu bestehenden JsonInputFormatter

Ich tat dies, aber frage mich, ob es einen besseren Weg ist:

services.AddMvc(mvcConfig => 
{ 
    var formatter = new JsonInputFormatter(); 
    formatter.SupportedMediaTypes.Add( 
     new MediaTypeHeaderValue("application/vnd.myget.webhooks.v1+json")); 
    mvcConfig.InputFormatters.Add(formatter); 
}); 

Antwort

3

Sie die Standard-InputFormatter in ConfigureServices

services.Configure<MvcOptions>(options => { 
    options.InputFormatters.OfType<JsonInputFormatter>().First().SupportedMediaTypes.Add(
     new MediaTypeHeaderValue("application/vnd.myget.webhooks.v1+json") 
    ); 
}); 

ändern kann ... vielleicht eine leichte Verbesserung

Verwandte Themen