Deploy and migration an ASP.NET MVC 4 with EF code first

Deploy and migrate an ASP.NET MVC 4 project with EF code first to an IIS 7.5 runing in a Windows Server

Phat Nguyen
IIS and Windows Server
2 min readJul 24, 2015

--

Use Visual studio 2013 as publishing tool.

Do the following step to deploy

First prepare your Server runs with IIS

  • Add IIS to your Server (choose ASP.NET and other need,… )
  • Make the .Net integration: run in cmd the following command:

%windir%\Microsoft.NET\Framework64\v4.0.30319\aspnet_regiis.exe -ir

  • Add a Website and re-config the Application Pool for this Webite runs with .NET 4.0.30319
  • Re-config the Site Bindings to route your Website URL
  • Install Web Deploy 3.6 (can install via Web platform installer)
  • Make sure your server .NET version must be higher than the application.

Second prepare your database server

I use SQL Server 2012 in the same IIS server, Database server can be a different server with IIS.

Just start all the database service and prepare your SQL user, connection string for the Third step.

Third use Visual studio to publish your Website

In this case I use VS 2013, and method One-click publish to publish my Website. My solution have 5 C# projects and 1 MVC Web project.

  • Right click on your MVC Web project and choose Publish…
  • Select a publish target: Custom -> Place a name for new profile.
  • Connection profile:– Server: your server IP or server domain
    – Site name: The name of Website you Add in your IIS server.
    – User name: Your Windows user / IIS user of server.
    – Password: The password of user.
    – Destination URL (not required): Your site URL.
  • Settings:
    – Configuration: Release / Debug when you use your server as Production / Test
    – Databases: Database context is your connection string in the Second step. My absolute database context is below.
    – Choose “Use this connection string at runtime” for Website in IIS server connect to Database server when runing (also update the destination web.config), and “Excute Code First Migrations” to the code first update your Database in Database server.

Data Source=(local);Initial Catalog=MyAppDB;Integrated Security=True;User ID=sa;Password=*****;MultipleActiveResultSets=True

  • Preview:
    Start Preview to see what files, folder will be uploaded to the IIS server and also confirm no Error in the solution.
  • Publish:
    – Wait to VS publish Website to IIS server.
    – VS will open your Destination URL to see your result.
    – DONE!

How about migration?

  • With the profile in deploy you just need to use Publish again to migrate your new things updated on IIS and database server.
  • Remember “Excute Code First Migrations” is chosen in Publish Web Settings.

How about the performence?

I use a server to run Windows server 2008, Microsoft SQL Server 2012, IIS server 7.5, the system requirement:

  • 45GB SSD (60GB is recommended)
  • CPU 2 cores 2.0 GHz (4 cores is recommended)
  • 2GB Ram (4GB is recommended)

--

--