How to enter content from a custom endpoint in my application's main tag?

Viewed 20

I am currently working on a system of creating posts that are saved in a database. The problem of displaying content written to the bank has already been resolved by using a custom Endpoint that processes a request and returns what it finds of content in the database related to the captured name. See the configuration of my endpoint.

Startup.cs

app.UseEndpoints(endpoints =>
      {
        endpoints.MapControllerRoute(
                  name: "default",
                  pattern: "{controller=Home}/{action=Index}/{id?}");
        endpoints.MapGet("Blog/post/{post}", EndPointPosts.Endpoint);
      });

EndPointPosts.cs

public static async Task Endpoint(HttpContext context)
    {
      string post = context.Request.RouteValues["post"] as string;
      var htmlResposta = CacheDePosts.ConsultarPostPeloNome(post.Replace('-', ' '), CultureInfo.CurrentCulture.Name);
      context.Response.ContentType = "text/html; charset=utf-8";
      StringBuilder html = new StringBuilder();
      html.Append(htmlResposta);
      await context.Response.WriteAsync(html.ToString());
    }

A request model processed by the endpoint

https://localhost:44328/Blog/post/What-is-Lorem-Ipsum?

enter image description here

The problem here is that I'm missing out on the default components of the application, such as header, menus, and footer. What I need is to insert this content and insert into the main tag of my _Layout.cshtml as with the other pages of my application.

0 Answers
Related