Navigation widget - make Redirect Pages redirect directly to destination url

by Vesselin Vassilev


Last Updated On May 23, 2021


Here is a scenario - you create a Redirect page that, let's say, you want to redirect to Google.com.

The page appears in the menu, but you notice that when you hover over that page in the menu, the target Url is not actually google.com, but it is the url of the page in Sitefinity, e.g. something like /redirect-to-google

When you click that link, two things are happening:

1. A request to the redirect page's url is sent to Sitefinity
GET /redirect-to-google

2. The response to that request is where the actual redirect is happening:
Status code 301, with a header:
location: https://google.com

To many end users, this is not expected, more often than not they would want the menu to render the Url of the destination page, e.g. google.com

This would also save an unnecessary request to the Sitefinity server.

There is already a KB article on how to change the WebForms navigation widget to achieve that. 

Below is how to do it for the MVC navigation widget.

Note: the NodeViewModel class does not contain info about the type of the Page (i.e. Standard or Redirect), but fortunately it gives us a reference to the PageSiteNode via the OriginalSiteMapNode property. 

From there we can easily get the destination url of any redirect page.

See the below GetUrl function that can be placed in the Navigation view:




Copyright © Sitefinity Development