TransWikia.com

Русские символы в ASP.Net Core

Stack Overflow на русском Asked by OverPie on February 13, 2021

Код "сервера":

using System.Net.Http.Headers;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;

namespace Server
{
    public class Startup
    {
        // This method gets called by the runtime. Use this method to add services to the container.
        // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
        public void ConfigureServices(IServiceCollection services)
        {
        }

        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            app.UseRouting();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapGet("/", async context =>
                {
                    await context.Response.WriteAsync("Съешь ещё этих мягких французских булок, да выпей же чаю.");
                });
            });
        }
    }
}

Но "сервер" выхлопнул не то, что мне нужно:
скриншот выхлопа сервера

Как заставить ASP.Net Core отправлять русские символы?

One Answer

Попробуйте добавить в заголовки кодировку:

endpoints.MapGet("/", async context =>
{
    context.Response.Headers["Content-Type"] = "text/plain; charset=utf-8";
    // ...
});

Correct answer by Exploding Kitten on February 13, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP