Can I modify the code that is called when a navigation item is clicked?

Topics: Core, Customizing Orchard
Jan 9, 2015 at 11:40 PM
Our Orchard site has a menu navigation item that links to our corporate knowledge base. We are going to require that the user be logged in before gaining access to the knowledge base. I'm wondering if its possible to modify the code so when the menu item is clicked it will do something like the following:
public knowledgebaseRedirect()
//generate url and add query string
string URL = "" + Sessionvariable(username)

redirect to URL

The session variable is something else we are working on. We are attempting to customize the login activities and then store the username as a session variable to pass to the knowledge base and another site of ours.
Jan 11, 2015 at 6:28 AM
Edited Jan 11, 2015 at 7:16 AM
As a starting point, you can copy the Core/Shapes/Views/MenuItemLink.cshtml in yourTheme/Views folder. In this file you have access to some dynamic data with the "Model" associated with the content part to render. In the context of the Orchard WebViewPage, you have also access to a more global WorkContext

So, as an example, replace
<a href="@Model.Href">@Model.Text</a>
        var href = (string)Model.Href;
        string text = Model.Text.ToString();
        var user = WorkContext.CurrentUser != null ? WorkContext.CurrentUser.UserName : "";
    @if (href.Contains("")) {
        if (!string.IsNullOrWhiteSpace(user)) {
            href = href + "?username=" + user;
            <a href="@href">@Model.Text</a>
        else {
            @Html.ActionLink(text, "LogOn", new { Controller = "Account",
                Area = "Orchard.Users", ReturnUrl = (Request.QueryString["ReturnUrl"] ??
                Request.RawUrl) }, new { rel = "nofollow" })
    else {
        <a href="@href">@Model.Text</a>
Note : Replace + with the plus sign

In the Dashboard Navigation page, you can also create a Shape MenuItem where you specify "YourShapeType", and create a YourShapeType.cshtml in your theme. This to override only this menu item. In this file, you will have access to the WorkContext, but you will have to hard code your url...

Note: With the WorkContext, you can also resolve many others services that you can use...