Code: Detail

Especializações:Asp.net, Ajax, C#, Visual Basic.net, Wcf, XML FrameWork .net 1.1, 2.0 e 4.0, OO, Design Patterns Arquitetura SOA, DDD, MVP e MVVM Html, Css, JavaScript Sql Server 2000, 2005 e 2008 Oracle 8i e 9i Asp3, Visual Basic 6 e COM+

netcore+webapi - (Portuguese)

Alterar resposta char-set utf-8 para us-ascii

Por padrão um serviço rest webapi retorna um json utilizando utf-8, este script que é implementado no metodo ConfigureServices da classe startup altera o charset da resposta para us-ascii

Last update: 18/07/2018
 
N/A
N/A
N/A
N/A
 

using Microsoft.AspNetCore.Mvc.Formatters;
using System.Text;

public class Startup
{
 
//--- CODIGO SEM IMPORTANCIA OMITIDO

       public void ConfigureServices(IServiceCollection services)
        {
            DependencyInjection.Register(services, Configuration);

            services.AddMvc(options => {
            options.Filters.Add(new ExceptionToApiResultFilter(false));


            //-----------------------------------------------------
            // Este trecho de codigo altera o charset 

                var jsonOutputFormatter = options.OutputFormatters
                    .OfType<JsonOutputFormatter>()
                    .First();

                jsonOutputFormatter.SupportedEncodings.Clear();
                jsonOutputFormatter.SupportedEncodings.Add(Encoding.GetEncoding("us-ascii"));

            //fim este trecho de codigo altera o charset
            //-------------------------------------------------
           
            });
        }

}

Source:
 
Users who have marked this routine as a favorite
 
 
 
The site ti4fun is not responsible for the content on sites for which you have external links

Articles, routines, tips, forums, blogs or any other content posted on ti4fun site is not tested and not validated, so you should test and validate any information collected on the ti4fun site before applying it to final use environment, such as example, production. the TI4FUN site is not responsible for quality or for any damages, direct, indirect or consequential, from use of any content posted by the authors in the site.

All content published on the ti4fun site is the responsibility of the author and do not necessarily express the views of the site ti4fun and its employees.