Click here to Skip to main content
15,886,919 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hello everyone good day I have a project with asp.net core I want to make a dynamic url structure in this project
route :
   endpoints.MapControllerRoute(
      name: "seourlparam",
      pattern: "{culture}/{seourl}",
      defaults: new { culture = "tr-TR", controller = "Home", action = "Index" }
  );


basecontroller :
public override async Task OnActionExecutionAsync( ActionExecutingContext context, ActionExecutionDelegate next)
{

    string seourl = context.RouteData.Values["seourl"] + "";
    string controllername = context.RouteData.Values["controller"] + "";
    string actionname = context.RouteData.Values["action"] + "";

    if(!string.IsNullOrEmpty(seourl) && controllername == "Home" && actionname == "Index")
    {
        var Sayfa = dbContext.Sayfas.FirstOrDefault(x => x.URL == seourl);

        if (Sayfa != null)
        {
            context.RouteData.Values["controller"] = Sayfa.ControllerName;
            context.RouteData.Values["action"] = Sayfa.ActionName;
        }

    }
    await base.OnActionExecutionAsync(context, next);

}

My problem is when I click on the link, for example, Controller: Page Action: Page Detail, but the view part is correct, but it sees the HomeController Index as the controller.
thank you if you help

What I have tried:

-My problem is when I click on the link, for example, Controller: Page Action: Page Detail, but the view part is correct, but it sees the HomeController Index as the controller.
thank you if you help
Posted
Updated 14-Jul-23 14:53pm

1 solution

Yes, this is why:
defaults: new { culture = "tr-TR", controller = "Home", action = "Index" }

You point to the home controller > controller = "Home"

Read more about Routing here: Routing to controller actions in ASP.NET Core | Microsoft Learn[^]

UPDATE

I have dug a bit deeper. This article should address your question: ASP.NET Core Culture Route Parameter[^]. It has this sample project: GitHub - DmitrySikorsky/AspNetCoreCultureRouteParameter: ASP.NET Core culture route parameter[^]
 
Share this answer
 
v2
Comments
burakkucukekiciler 15-Jul-23 5:03am    
[Route("Page/SayfaDetay")] Iactionresult SayfaDetay
[Route("Blog/BlogDetay")] Iactionresult BlogDetay
but still home index controller works
Graeme_Grant 15-Jul-23 5:07am    
Did you read the page link that I posted?
burakkucukekiciler 15-Jul-23 5:15am    
I read but I made this project with asp.net I used the same system but it was working but when I migrate asp.net core it gives an error

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900