asp.net core how can I stop http request from locking

前端 未结 1 328
难免孤独
难免孤独 2021-01-15 05:16

I am new to asp.net Core and so far I like it . I have a very simple action that just returns a string \"Hello World\" . My problem is that I think that http request are loc

1条回答
  •  一生所求
    2021-01-15 05:45

    If all you are doing is trying to return a simple string and load testing the underlying host then I would suggest you remove all the middleware and services

    using System.Net;
    using Microsoft.AspNetCore;
    using Microsoft.AspNetCore.Hosting;
    using Microsoft.AspNetCore.Builder;
    using Microsoft.AspNetCore.Http;
    
    public static void Main(string[] args)
    {
        IWebHost host = new WebHostBuilder()
            .UseKestrel()
            .Configure(app =>
            {
                // notice how we don't have app.UseMvc()?
                app.Map("/hello", SayHello);  // <-- ex: "http://localhost/hello"
            })
            .Build();
    
        host.Run();
    }
    
    private static void SayHello(IApplicationBuilder app)
    {
        app.Run(async context =>
        {
            // implement your own response
            await context.Response.WriteAsync("Hello World!");
        });
    }
    

    0 讨论(0)
提交回复
热议问题