Base solution for your next web application
Open Closed

How can I dynamic generate URL within NavigationProvider? #1111


User avatar
0
winson created

I need to dynamic to generate the URL with URL route, because I need to handle the root or subfolder deployment issue, so I want to generate url like below:

UrlHelper url = new UrlHelper(HttpContext.Current.Request.RequestContext);

var menuUrl= url.RouteUrl(new { Controller = "Home", Action = "Index" });

new MenuItemDefinition(
                        "Home",
                        new FixedLocalizableString("Home"),
                        url: menuUrl,
                        icon: "fa fa-home",
UserRole.JOURNALIST
                        )

but it's can't get the HttpContext.Current.Request.RequestContext in NavigationProvider class, so any ideas?

Thanks!


2 Answer(s)
  • User Avatar
    0
    hikalkan created
    Support Team

    Hi,

    That's not possible since menu is created on application initialization, not per request. You can do it while rendering menu (in razor view).

  • User Avatar
    0
    winson created

    ok, I see, thank you!!