Easy Steps to Migrate an ASP.NET MVC Project to ASP.NET Core Project
Tags: csharp, dotnet, webdev, productivity
Published: 2021-08-05 11:37:24

---
title: Easy Steps to Migrate an ASP.NET MVC Project to ASP.NET Core Project
published: true
date: 2021-08-05 11:00:56 UTC
tags: csharp, dotnet, webdev, productivity
canonical_url: https://www.syncfusion.com/blogs/post/migrate-asp-net-mvc-project-to-asp-net-core.aspx
cover_image: https://www.syncfusion.com/blogs/wp-content/uploads/2021/08/Easy-Steps-to-Migrate-an-ASP.NET-MVC-Project-to-ASP.NET-Core-Project-672x372.png
---

[ASP.NET MVC](https://en.wikipedia.org/wiki/ASP.NET_MVC "Link to ASP.NET MVC Wikipedia page") is a framework for developing web applications. It works on the model-view-controller pattern, and you can use it to develop only on Windows systems.

On the other hand, [ASP.NET Core](https://en.wikipedia.org/wiki/ASP.NET_Core "Link to ASP.NET Core Wikipedia page") is a cross-platform web development framework that supports developing applications on Windows, Mac, Linux, iOS, and Android platforms. It has less maintenance, high performance, and more versatile features compared to the ASP.NET MVC.

In this blog post, we are going to learn how to upgrade an ASP.NET MVC web application by migrating it to ASP.NET Core by following these simple steps:

1. [Create an ASP.NET MVC sample project](#create-an-asp-net-mvc-sample-project).
2. [Create an ASP.NET Core sample project](#create-an-asp-net-core-sample-project).
3. [Migrate a register and login page to ASP.NET Core](#migrate-register-and-login-page-to-asp-net-core).
4. [Migrate views and controllers to ASP.NET Core](#migrate-views-and-controllers-to-asp-net-core).
5. [Migrate all layout files to ASP.NET Core](#migrate-the-layout-files-to-asp-net-core).
6. [Test each action method in the Home controller](#test-each-action-method-in-the-home-controller).

## Prerequisites

- [Visual Studio 2019 16.4 or later with the ASP.NET and Web development workload](https://visualstudio.microsoft.com/downloads/?utm_medium=microsoft&utm_source=docs.microsoft.com&utm_campaign=inline+link&utm_content=download+vs2019 "Link to Microsoft Visual Studio").
- [.NET Core 3.1 SDK or later](https://dotnet.microsoft.com/download/dotnet/3.1 "Link to download .NET Core 3.1 Core SDK").

## Create an ASP.NET MVC sample project

First, we are going to create a simple ASP.NET MVC project by following these steps:

1. Open Visual Studio and open the  **File**  menu. Then, navigate to  **New ->**   **Project**.
2. Now, select **ASP.NET Web Application (.NET Framework)** and click  **Next**.
3. Name the project MVC_WebApplication1,_ so that the namespace matches the ASP.NET Core project that will be created later in this blog post. Now, click  **Create**.
4. Next, select the  **MVC** option, and then click  **Create**.
5. Finally, run the application.  
 ![Create a Simple ASP.NET MVC Project](https://www.syncfusion.com/blogs/wp-content/uploads/2021/08/Create-a-Simple-ASP.NET-MVC-Project.png)

We have created a simple ASP.NET MVC project.

## Create an ASP.NET Core sample project

Now, we are going to create a simple ASP.NET Core project.

1. In Visual Studio, open the  **File**  menu and then navigate to  **New ->**   **Project**.
2. Now, select the  **ASP.NET Core Web Application**  option and click  **Next**.
3. Then, the  **Configure your new project**  dialog will open. In it, enter the project name Core_WebApplication1_. Using the same namespace makes it easier to copy code between the two projects. Now, click  **Create**.
4. In the  **Create a new ASP.NET Core Web Application**  dialog, confirm that the  **.NET Core**  and  **ASP.NET Core 3.1**  options are selected. Then, select the **Web Application (Model-View-Controller)** project template and click  **Create**.
5. Finally, run the application.  
 ![Creating a Simple ASP.NET Core Project](https://www.syncfusion.com/blogs/wp-content/uploads/2021/08/Creating-a-Simple-ASP.NET-Core-Project.png)

We have created a basic ASP.NET Core project.

## Migrate register and login page to ASP.NET Core

In this section, we are going to migrate a register and login page to ASP.NET Core. Let’s get started.

1. For authentication and identity features, install the following NuGet packages in ASP.NET Core:
  - [Microsoft.AspNetCore.Identity.EntityFrameworkCore](https://www.nuget.org/packages/Microsoft.AspNetCore.Identity.EntityFrameworkCore "Link to Microsoft.AspNetCore.Identity.EntityFrameworkCore NuGet package")
  - [Microsoft.AspNetCore.Authentication.Cookies](https://www.nuget.org/packages/Microsoft.AspNetCore.Authentication.Cookies/ "Link to Microsoft.AspNetCore.Authentication.Cookies NuGet package")
  - [Microsoft.EntityFrameworkCore.SqlServer](https://www.nuget.org/packages/Microsoft.EntityFrameworkCore.SqlServer/ "Link to Microsoft.EntityFrameworkCore.SqlServer NuGet package")
2. In the **Startup.cs** file, add the **Startup.ConfigureService** method to use the Entity Framework and Identity services as shown in the following code:
```csharp
public void ConfigureServices(IServiceCollection services)
{
    // Add EF services to the services container.
    services.AddDbContext<ApplicationDbContext>(options =>
        options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));

    services.AddIdentity<ApplicationUser, IdentityRole>()
        .AddEntityFrameworkStores<ApplicationDbContext>()
        .AddDefaultTokenProviders();

     services.AddMvc();
}
```
3. Create a **Models** folder in the ASP.NET Core project and add the two classes **ApplicationUser** and **ApplicationDBContext** to their corresponding references from the ASP.NET MVC project. You can find these classes together in the **Models/IdentityModels.cs** file path in the ASP.NET MVC project.  
Refer to the following screenshot.  
 ![Add the two classes ApplicationUser and ApplicationDBContext to their corresponding references from the ASP.NET MVC project](https://www.syncfusion.com/blogs/wp-content/uploads/2021/08/add-the-two-classes-ApplicationUser-and-ApplicationDBContext-to-their-corresponding-references-from-the-ASP.NET-MVC-project.png)Also, you can create separate classes for these classes as shown in the following code samples:  
**ApplicationUser.cs:**
```csharp
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;

namespace NewMvcProject.Models
{
  public class ApplicationUser : IdentityUser
  {
  }
}
```

**ApplicationDBContext.cs:**

```csharp
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
using Microsoft.Data.Entity;

namespace NewMvcProject.Models
{
    public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
    {
        public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options)
            : base(options)
        {
        }

        protected override void OnModelCreating(ModelBuilder builder)
        {
            base.OnModelCreating(builder);
            // Customize the ASP.NET Core Identity model and override the defaults if needed.
            // For example, you can rename the ASP.NET Core Identity table names and more.
            // Add your customizations after calling base.OnModelCreating(builder);
        }
    }
}
```
4. Add the following namespaces in the **Startup.cs** file to compile:
```csharp
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Hosting;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
```
5. Add a new Razor view called **\_LoginPortal** to the **Views -> Shared** folder and include the following code:
```js
@inject SignInManager<ApplicationUser> SignInManager
@inject UserManager<ApplicationUser> UserManager

@if (SignInManager.IsSignedIn(User))
{
    <form asp-area="" asp-controller="Account" asp-action="Logout" method="post" id="logoutForm" class="navbar-right">
        <ul class="nav navbar-nav navbar-right">
            <li>
                <a asp-area="" asp-controller="Manage" asp-action="Index" title="Manage">Hello @UserManager.GetUserName(User)!</a>
            </li>
            <li>
                <button type="submit" class="btn btn-link navbar-btn navbar-link">Log out</button>
            </li>
        </ul>
    </form>
}
else
{
    <ul class="nav navbar-nav navbar-right">
        <li><a asp-area="" asp-controller="Account" asp-action="Register">Register</a></li>
        <li><a asp-area="" asp-controller="Account" asp-action="Login">Log in</a></li>
    </ul>
}
```

## Migrate views and controllers to ASP.NET Core

Let’s migrate the views and controllers to the ASP.NET Core project with these simple steps:

1. Navigate to **Views -> Home** directory. Then, add the **About.cshtml** , **Contact.cshtml** , and **Index.cshtml** view files from the ASP.NET MVC project.
2. Then, in the **Controllers -> HomeController.cs** file, add all the methods from the ASP.NET MVC project.

## Migrate the layout files to ASP.NET Core

Now, we are going to migrate all the layout files from the ASP.NET MVC project to the ASP.NET Core project.

1. In the **Views** folder, add the **\_ViewStart.cshtml** file from the ASP.NET MVC project.
2. Then, in the **Views -> Shared** folder, add the **\_Layout.cshtml** file from the ASP.NET MVC project.
3. Make the following changes in the **\_Layout.cshtml** file:
  - Replace the **@Styles.Render(“~/Content/css”) **code with the following:
```html
<link rel="stylesheet"
        href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"
        integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u"
        crossorigin="anonymous">
```
  - Remove the **@Scripts.Render(“~/bundles/modernizr”)** code.
  - Then, replace the **@Scripts.Render(“~/bundles/jquery”)** and **@Scripts.Render(“~/bundles/bootstrap”)** code with the following:
```html
<script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
       <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"
       integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
```

## Test each action method in the Home controller

Now, run the ASP.NET Core application.

![Run the ASP.NET Core Project](https://www.syncfusion.com/blogs/wp-content/uploads/2021/08/Run-the-ASP.NET-Core-Project.png)Then, navigate to the **Home** , **About** , **Contact** , **Login** , and **Register** tabs to ensure the changes are correct. Refer to the following screenshots.

**About:**

**![Check the About tab](https://www.syncfusion.com/blogs/wp-content/uploads/2021/08/Check-the-About-tab-1.png)Contact:**

## ![Check the Contact tab](https://www.syncfusion.com/blogs/wp-content/uploads/2021/08/Check-the-Contact-tab-1.png)

## Conclusion

Thanks for reading! In this blog post, we have learned how to migrate an ASP.NET MVC project to an ASP.NET Core project. By doing so, you can create cross-platform apps for Windows, Mac, Linux, iOS, and Android platforms. So, try out the process yourself and leave your feedback in the comments section of this blog post!

With over 70 components, our Syncfusion [ASP.NET Core](https://www.syncfusion.com/aspnet-core-ui-controls "Link to ASP.NET Core UI controls") toolkit powered by [Essential JS 2](https://www.syncfusion.com/javascript-ui-controls "Link to Essential JS 2 UI controls") contains all you need for building line-of-business applications. It includes popular widgets such as a [DataGrid](https://www.syncfusion.com/aspnet-core-ui-controls/grid "Link to ASP.NET Core DataGrid"), [Charts](https://www.syncfusion.com/aspnet-core-ui-controls/charts "Link to ASP.NET Core Charts"), [Gantt Chart](https://www.syncfusion.com/aspnet-core-ui-controls/gantt-chart "Link to ASP.NET Core Gantt Chart"), [Diagram](https://www.syncfusion.com/aspnet-core-ui-controls/diagram "Link to ASP.NET Core Diagram"), [Spreadsheet](https://www.syncfusion.com/aspnet-core-ui-controls/spreadsheet "Link to ASP.NET Core Spreadsheet"), [Scheduler](https://www.syncfusion.com/aspnet-core-ui-controls/scheduler "Link to ASP.NET Core Scheduler"), and [Pivot Table](https://www.syncfusion.com/aspnet-core-ui-controls/pivot-table "Link to ASP.NET Core Pivot Table"). Use them to enhance your productivity!

For existing customers, the new version is available for download from the [License and Downloads](https://www.syncfusion.com/account/downloads "Link to license and download page of Essential Studio") page. If you are not yet a Syncfusion customer, you can try our 30-day [free trial](https://www.syncfusion.com/downloads "Link to the free evaluation of the Syncfusion Essential Studio") to check out the available features. Also, we encourage you to try our samples on [GitHub](https://github.com/syncfusion "Link to the Syncfusion examples on GitHub").

Also, you can contact us through our [support forum](https://www.syncfusion.com/forums "Link to the Syncfusion support forum"), [Direct-Trac](https://www.syncfusion.com/support/directtrac/incidents "Link to the Syncfusion support system Direct Trac"), or [feedback portal](https://www.syncfusion.com/feedback "Link to Syncfusion Feedback Portal"). We are always happy to assist you!

## Related blogs

- [How to Migrate ASP.NET HTTP Handlers and Modules to ASP.NET Core Middleware](https://dev.to/syncfusion/how-to-migrate-asp-net-http-handlers-and-modules-to-asp-net-core-middleware-27lc "Link to How to Migrate ASP.NET HTTP Handlers and Modules to ASP.NET Core Middleware blog")
- [How to Migrate SQL Server in an ASP.NET MVC Application to MySQL and PostgreSQL](https://www.syncfusion.com/blogs/post/how-to-migrate-sql-server-in-an-asp-net-mvc-application-to-mysql-and-postgresql.aspx "Link to How to Migrate SQL Server in an ASP.NET MVC Application to MySQL and PostgreSQL blog")
- [How to Apply API Versioning in ASP.NET Core](https://dev.to/karthickramasamy08/how-to-apply-api-versioning-in-asp-net-core-3fig-temp-slug-5071663 "Link to How to Apply API Versioning in ASP.NET Core blog")
- [How to Add Stored Procedures in ASP.NET Core Apps Using SPToCore](https://dev.to/syncfusion/how-to-add-stored-procedures-in-asp-net-core-apps-using-sptocore-3a3o "Link to How to Add Stored Procedures in ASP.NET Core Apps Using SPToCore blog")