CodexBloom - Programming Q&A Platform

How to Handle 'how to use a leading .. to exit' handling in ASP.NET Core MVC with Nested Routes?

👀 Views: 72 đŸ’Ŧ Answers: 1 📅 Created: 2025-06-12
asp.net-core mvc routing error-handling csharp

I've been struggling with this for a few days now and could really use some help. I'm developing an ASP.NET Core MVC application using version 7.0, and I've run into an scenario when trying to navigate to a specific view through nested routes. My application has a structure where I want to access a child resource via a URL like `/products/{productId}/reviews/{reviewId}`. However, when I attempt to access this route, I receive the behavior message: `want to use a leading .. to exit the top directory`. I've set up my routes in `Startup.cs` like this: ```csharp app.UseRouting(); app.UseEndpoints(endpoints => { endpoints.MapControllerRoute( name: "reviews", pattern: "products/{productId}/reviews/{reviewId}", defaults: new { controller = "Reviews", action = "Index" } ); }); ``` The `ReviewsController` looks like this: ```csharp public class ReviewsController : Controller { public IActionResult Index(int productId, int reviewId) { // Fetch product and review data return View(); } } ``` I've double-checked that I'm passing valid `productId` and `reviewId` values in my links, which I generate using `@Url.Action` in my Razor view: ```html <a href="@Url.Action("Index", "Reviews", new { productId = product.Id, reviewId = review.Id })">View Review</a> ``` To debug, I also tried hardcoding the URL in my browser, but the same behavior continues. I suspect the scenario might be related to the configuration of my routing, but I'm not sure how to properly set it up for nested resources. Could anyone provide insights or examples on how to resolve this behavior while maintaining a clean route structure? For context: I'm using Csharp on Ubuntu. I'm working on a service that needs to handle this. Has anyone else encountered this?