QwarkDev

ASP Service quick start (.NET 5.0)

Nov 24th, 2020
678
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. /*
  3.   ASP.NET Base for service
  4.   .ASP.NET 5.0
  5.   Author - aws (qwark)
  6. */
  7.  
  8. using Microsoft.AspNetCore;
  9. using Microsoft.AspNetCore.Builder;
  10. using Microsoft.AspNetCore.Hosting;
  11. using Microsoft.AspNetCore.Http;
  12. using Microsoft.Extensions.Hosting;
  13. using Microsoft.Extensions.Logging;
  14. using System;
  15. using System.Collections.Generic;
  16. using System.Linq;
  17. using System.Threading.Tasks;
  18. using System.Text.Json;
  19. using System.Text.Json.Serialization;
  20.  
  21. string ToJson(object obj)
  22. {
  23.     return JsonSerializer.Serialize(obj);
  24. }
  25.  
  26. WebHost.CreateDefaultBuilder()
  27.     .Configure(x =>
  28.     {
  29.         x.Map("/api", z => z.Run((context) =>
  30.         {
  31.             return context.Response.WriteAsync($"Hello. Its root page of service\n" +
  32.                 $"Request query: {ToJson(context.Request.Query)}\n");
  33.         }));
  34.         x.Map("", z => z.Run((context) =>
  35.         {
  36.             return context.Response.WriteAsync("aws service\nUse /api for more info...");
  37.         }));
  38.     })
  39.     .UseUrls("http://localhost:1010")
  40.     .Build().Run();
  41.  
  42.  
RAW Paste Data