Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

400
Views
¿Cómo ver el nombre del punto final de HttpContext?

Digamos que tengo una aplicación de página de afeitar, y hay una página de afeitar "Producto.cshtml", ¿cómo puedo ver la cadena "Producto.cshtml" en el objeto HttpContext (asumiendo que puedo acceder al objeto HttpContext en el middleware antes del middleware de punto final como muestra el siguiente código)? Traté de usar el método de extensión EndpointHttpContextExtensions.GetEndpoint(HttpContext) , aún no pude encontrar nada que pudiera contener "Product.cshtml".

 // startup.cs public void Configure(IApplicationBuilder app, IWebHostEnvironment env) { app.UseRouting(); app.UseMiddleware<GetEndPointMiddleWare>(); app.UseEndpoints(endpoints => { endpoints.MapRazorPages(); }); } public class GetEndPointMiddleWare { private RequestDelegate next; public QueryStringMiddleWare(RequestDelegate nextDelegate) { next = nextDelegate; } public async Task Invoke(HttpContext context) { ... await next(context); // I want to print "Product.cshtml" here // var endpoint = EndpointHttpContextExtensions.GetEndpoint(context); // <---- didn't find any property that has the string I want } }
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

La ruta a la página está dentro de los metadatos del punto final como parte de un objeto PageActionDescriptor , por lo que se puede acceder y analizar. Un ejemplo de middleware que inspecciona la ruta de la página:

 // Startup.cs -> Configure() app.UseRouting(); app.Use(next => context => { var endpoint = context.GetEndpoint(); if (endpoint is null) { return Task.CompletedTask; } if (endpoint.Metadata.FirstOrDefault(i => i is PageActionDescriptor) is PageActionDescriptor pageDescriptor) { string pagePath = pageDescriptor.RelativePath; Console.WriteLine($"Page path: {pagePath}"); // '/Pages/Product.cshtml' } return Task.CompletedTask; }); app.UseEndpoints(endpoints => { endpoints.MapRazorPages(); endpoints.MapDefaultControllerRoute(); });

(Adaptado del ejemplo de documentos )

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!