To Work both Json And XML in Asp.Net Core Web Api.

Both json And Xml Working for My Api Just Need to Add Few More Nuget Packages Correct Version for The Project Setup Thats All 1. add it to ....

Both json And Xml Working for My Api Just Need to Add Few More Nuget Packages Correct Version for The Project Setup Thats All 1. add it to .csproj 2. add Some Nuget Packages 1.Microsoft.AspNetCore.Mvc.Formatters.Json 2.Microsoft.AspNetCore.Mvc.Formatters.xml 3.Microsoft.AspNetCore.All (2.2.2) 3. Add On StartUp.cs services.AddMvc(options => { options.FormatterMappings.SetMediaTypeMappingForFormat ("xml", MediaTypeHeaderValue.Parse("application/xml")); options.FormatterMappings.SetMediaTypeMappingForFormat ("config", MediaTypeHeaderValue.Parse("application/xml")); options.FormatterMappings.SetMediaTypeMappingForFormat ("js", MediaTypeHeaderValue.Parse("application/json")); }) .AddXmlSerializerFormatters(); 4.Add On StartUp.CS using Microsoft.Net.Http.Headers; 5. On top Of Api Controller [FormatFilter] [ApiController] [Route("api/products")] on getby id Method [HttpGet("{id}.{format?}"),FormatFilter] YOu All Done Now the Default Will be Json And if YOu Want to Use Xml then add ?format=xml https://andrewlock.net/formatting-response-data-as-xml-or-json-based-on-the-url-in-asp-net-core/ https://youtu.be/yhvLBmwSDNg

COMMENTS

BLOGGER: 2
Loading...
Name

উইন্ডোজের ১০টি ফ্রি সফটওয়্যার যা আপনার লাগবেই,1,
ltr
item
শিখবে সবাই - গড়বে দেশ ,সমৃদ্ধ বাংলাদেশ: To Work both Json And XML in Asp.Net Core Web Api.
To Work both Json And XML in Asp.Net Core Web Api.
শিখবে সবাই - গড়বে দেশ ,সমৃদ্ধ বাংলাদেশ
http://merjporosh.blogspot.com/2019/09/to-work-both-json-and-xml-in-aspnet.html
http://merjporosh.blogspot.com/
http://merjporosh.blogspot.com/
http://merjporosh.blogspot.com/2019/09/to-work-both-json-and-xml-in-aspnet.html
true
4770289432660120729
UTF-8
Loaded All Posts Not found any posts VIEW ALL Readmore Reply Cancel reply Delete By Home PAGES POSTS View All RECOMMENDED FOR YOU LABEL ARCHIVE SEARCH ALL POSTS Not found any post match with your request Back Home Sunday Monday Tuesday Wednesday Thursday Friday Saturday Sun Mon Tue Wed Thu Fri Sat January February March April May June July August September October November December Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec just now 1 minute ago $$1$$ minutes ago 1 hour ago $$1$$ hours ago Yesterday $$1$$ days ago $$1$$ weeks ago more than 5 weeks ago Followers Follow THIS PREMIUM CONTENT IS LOCKED STEP 1: Share. STEP 2: Click the link you shared to unlock Copy All Code Select All Code All codes were copied to your clipboard Can not copy the codes / texts, please press [CTRL]+[C] (or CMD+C with Mac) to copy