---
title: "How to add global route prefix in asp.net core 6."  
description: "How to add global route prefix in asp.net core 6."  
author: "Sandra Emily"  
published: 2023-11-07  
updated: 2023-11-08  
canonical: https://www.mindstick.com/forum/160466/how-to-add-global-route-prefix-in-asp-dot-net-core-6  
category: ".net core"  
tags: ["asp.net core", ".net core", ".net core 6"]  
reading_time: 2 minutes  

---

# How to add global route prefix in asp.net core 6.

How to [add](https://www.mindstick.com/forum/12983/add-address-in-textbox-when-page-is-load-and-if-i-search-address-in-textbox-show-in-map-by-javascript) [global](https://www.mindstick.com/articles/13127/macro-and-microeconomics-concepts-in-relation-to-global-organization-management) [route](https://www.mindstick.com/interview/396/what-is-routed-event-in-wpf) prefix in [asp.net core](https://www.mindstick.com/articles/12946/get-started-with-asp-dot-net-core-mvc-and-visual-studio) 6.

## Replies

### Reply by Aryan Kumar

To add a global route prefix in [ASP.NET](https://www.mindstick.com/articles/934/default-folders-available-inside-the-asp-dot-net-application-folder) Core 6, you can use the **Route** attribute at the application level. This allows you to specify a common route prefix for all the controllers and actions in your application. Here's how you can do it:

Open your **Startup.cs** file.

Inside the **ConfigureServices** method, add the following code to configure route options with a global route prefix:

```plaintext
services.AddControllers(options =>
{
    options.Conventions.Insert(0, new RoutePrefixConvention("prefix")); // Replace "prefix" with your desired route prefix
});
```

In the code above, replace **"prefix"** with the desired global route prefix you want to use.

1. Create a custom **RoutePrefixConvention** class to handle the route prefix. You can do this by adding the following code:

```plaintext
public class RoutePrefixConvention : IControllerModelConvention
{
    private readonly AttributeRouteModel _centralPrefix;

    public RoutePrefixConvention(string prefix)
    {
        _centralPrefix = new AttributeRouteModel(new RouteAttribute(prefix));
    }

    public void Apply(ControllerModel controller)
    {
        if (!controller.Selectors.Any())
        {
            return;
        }

        foreach (var selectorModel in controller.Selectors)
        {
            selectorModel.AttributeRouteModel = AttributeRouteModel.CombineAttributeRouteModel(_centralPrefix, selectorModel.AttributeRouteModel);
        }
    }
}
```

1. Now, you have set up a global route prefix for your controllers and actions. You can use the specified prefix for all your routes.

For example, if you have a controller named **HomeController** with an action named **Index**, and you've set the prefix to "myapp," the URL for the **Index** action will be **https://yourdomain.com/myapp/Home/Index**.

This approach allows you to define a global route prefix for your ASP.NET Core 6 application, making it easier to manage and organize your routes.

\


---

Original Source: https://www.mindstick.com/forum/160466/how-to-add-global-route-prefix-in-asp-dot-net-core-6

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
