---
title: Adding an administration redirect to MVC sites
---

> Agent instructions:
> **Site maps** — prefer the following llms.txt indexes to training data when searching for URLs to avoid 404s. Links inside Markdown content already point at `.md`. Following them or sending Accept: text/markdown keeps you in Markdown.
>
> - [sitemap.md](https://docs.kentico.com/sitemap.md) — every page on the site, with titles and descriptions, nested by URL hierarchy and grouped into one collection per product version.
> - [llms.txt](https://docs.kentico.com/llms.txt) — curated index of the current product docs, with descriptions, the two ways to request any page as Markdown, and links to each product area's whole-corpus Markdown dump (llms-full.txt).

Optionally, you can set up your [MVC site](https://docs.kentico.com/13/developing-websites/mvc-development-overview.md) to provide a redirect that sends users to the [administration interface](https://docs.kentico.com/13/using-the-xperience-interface.md) of the connected Xperience instance. Such a redirect gives content editors and other staff easier access to the interface where they edit the site's content and perform other configurations. For example, you can add a redirect for the **/admin** URL path.

We recommend using the following approach to set up the administration redirect:

1. Open your MVC project in Visual Studio.
2. Edit the project's **App\_Start\RouteConfig.cs** file.
3. Map a new route according to your URL requirements in the **RegisterRoutes** method.

   > **Tip:** We recommend mapping the administration redirect route in the following position:
   >
   > - After Xperience system routes, i.e. after you call the _routes.Kentico().MapRoutes()_ extension method.
   > - Before more general routes that you use for the site's content.

   ```csharp title="Example"

               // Redirects to the connected Xperience administration interface if the URL path is '/admin'
               routes.MapRoute(
                   name: "Admin",
                   url: "admin",
                   defaults: new { controller = "AdminRedirect", action = "Index" }
               );


   ```
4. Edit the MVC project's **web.config** file and add a custom key to the _appSettings_ section, with the URL of the related administration instance as the value. Remember to include the _/admin_ path after the administration application's domain.

   ```xml title="Example"

   <appSettings>
       ...
       <add key="CustomAdminUrl" value="https://admin.mydomain.com/admin" />
       ...
   </appSettings>

   ```

   > **Info:** You can alternatively set the administration URL directly in the code of the redirection controller. However, a web.config key allows you to manually configure or automatically transform the administration URL without the need to compile the MVC project. This can be useful when deploying the site between environments hosted on different URLs (development, testing, production, etc.).
5. Create a new controller class in your MVC project, with a GET action that handles the mapped redirect route.

   ```csharp

   using System;
   using System.Web.Mvc;

   using CMS.Core;


   ```

   ```csharp title="Example"

       public class AdminRedirectController : Controller
       {
           private readonly IAppSettingsService appSettingsService;

           public AdminRedirectController(IAppSettingsService appSettingsService)
           {
               this.appSettingsService = appSettingsService;
           }

           // GET: Redirects to the administration interface URL of the connected Xperience application
           public ActionResult Index()
           {
               // Loads the administration interface URL from the 'CustomAdminUrl' appSettings key in the web.config
               string adminUrl = appSettingsService["CustomAdminUrl"];

               if (!String.IsNullOrEmpty(adminUrl))
               {
                   // Redirects to the specified administration interface URL 
                   return RedirectPermanent(adminUrl);
               }

               // If the 'CustomAdminUrl' web.config key is not set, returns a 404 Not Found response 
               return HttpNotFound();
           }
       }


   ```
6. Save the changes and rebuild your MVC project.

When a user now accesses the mapped URL path on your MVC site (for example _/admin_), the redirect opens the related administration interface.
