🚀 Welcome to MDriven Learn –  MDriven is now on Discord!  Don’t miss the latest Release Notes.
Redirection page
This page was created by Lars.olofsson on 2020-08-08. Last edited by Wikiadmin on 2026-07-29.

You can handle requests for unavailable or incorrect URLs in a Turnkey web application by creating a RedirectView ViewModel that shows guidance, routes users to a valid page, or implements application-specific URL shortcuts.

How redirection works

When a user requests a page that Turnkey cannot resolve, the Turnkey server redirects the request to the ViewModel named RedirectView. Use this ViewModel as the application's common destination for unavailable URLs and request errors.

For example, a user who follows an outdated link can see a message explaining that the requested page is unavailable and a way to return to the application's default Index page.

The error is handled by the MVC controller in the Turnkey server. You do not need to add web.config configuration for this behavior.

Create the RedirectView

  1. In MDriven Designer, create a ViewModel named RedirectView. The name is significant: Turnkey uses this ViewModel when it redirects an unresolved request.
  2. Add the variables described in Receive request information so that the ViewModel can inspect the incoming path and error code.
  3. Design the ViewModel to present a user-facing message and navigation appropriate for your application.
  4. Test the result by requesting a URL that does not map to an application page.

Show a useful error page

Use RedirectView to explain what happened without exposing implementation details. Give the user a clear next step, such as returning to the default page or choosing another known page.

For example, RedirectView can display:

The page you requested is not available.
Return to the start page and continue from there.

This pattern is appropriate when the application cannot determine a valid replacement for the requested URL. A user-friendly not-found message is particularly useful for requests that result in an error such as 400.

Receive request information

Add the following string variables to RedirectView. Turnkey fills them when it sends the request to this ViewModel.

Variable Value received Example use
RawURL The URL path that caused the redirect or error. Show a generic message while using the path to decide whether an old URL has a replacement.
ErrorCode The error code associated with the request. Display different guidance for known error cases, such as 400.

Treat RawURL and ErrorCode as request context. Use them to select behavior; do not require the user to interpret them.

Redirect a known obsolete URL

RedirectView can also act as a decision point for known paths. Add lookup logic that evaluates RawURL and then invokes the appropriate action for the matching case.

For example, if an earlier application URL should now open a different ViewModel, create an action for that case and configure the action button with an interval of 10 ms. The action can then redirect the user to the correct page without requiring a manual button click.

You can create multiple actions when different outdated paths require different destinations. This also lets you implement application shortcuts: a recognized short path can enter RedirectView and then be redirected to the relevant page.

Keep a fallback message for paths that do not match any lookup rule. Without a known destination, return the user to a safe navigation choice rather than attempting an arbitrary redirect.

DisplayWithVariables behavior

The redirect mechanism uses DisplayWithVariables to open RedirectView and provide the error code. DWV is the short form of DisplayWithVariables. In this scenario it does not require a root object, because no root object is available for the redirect request.

Routes and navigation

When you change or adopt URL formats, review Documentation:Improved routes. Improved routes provide shorter application, MVC, and REST URL forms; the older routes continue to function. RedirectView is the appropriate place to handle links that no longer resolve after a route or application change.

For normal in-application movement, use Documentation:Navigation rather than treating RedirectView as a general navigation mechanism. For action design, see Documentation:Actions Editor.

See also