Want to know how you can get started quickly with ASP.NET Core 1.0 and run it on Azure Web Apps?
Then this is the post for you :)
I'll be doing a small series on ASP.NET Core and .NET Core now that 1.0 is out.
Possible topics I have in mind:
- The different tools (VS2015, VS Code, Yeoman)
- Configuration system (and how can you use App Service settings to override them) - DONE
- APIs on ASP.NET Core - DONE
- Azure AD and ASP.NET Core - DONE
- And whatever comes to my mind :)
- Visual Studio 2015: You can download the Community Edition here
- VS 2015 Update 3: If you did not get it from the previous step (or already had VS2015), download it from here
- .NET Core tools for VS2015: Download from here
Creating the project
To create the project, open Visual Studio 2015.
In the New Project dialog select Templates -> Visual C# -> Web -> ASP.NET Core Web Application (.NET Core). Give the project a name and choose its location. Click Create.
In the creation dialog, you can choose which basic template you want:
- Empty: Literally empty project. Choose if you want to start from scratch.
- Web API: Choose if you want to create an API.
- Web Application: Choose if you want to create a user-facing web application.
- Note that you can mix API and user-facing application also, they are both in the same framework.
- In this example, I will use this template with individual user accounts
Note that you can also choose what kind of authentication you want with the Web API and Web Application options.
After the library restore is done, you can start the app through Debug -> Start Debugging.
I clicked the button that says Register to create a test user account. Now after I clicked the button I thought "Wait so what about DB migrations?". And I was greeted with this:
"Is that a button for running the migrations???" Yes it is. Whoever made this error page, you deserve a medal. After clicking that and refreshing the page, everything was working as expected.
Publishing to Azure
First I created the Web App + Azure SQL Database in Azure Portal. This is quite easy to do with the Web App + Azure SQL Database template.
Go back to VS2015, and stop debugging and right-click on the project. Find the option Publish....
Select Microsoft Azure App Service as target. Log in with your Azure credentials, select the existing app you want to publish to, or create a new one.
Now you can go through the Publish dialog as usual, but on the last page we have some options:
I chose to change the connection string here because I have not tested how loading the connection strings at runtime from App Service works yet.
I also chose to run migrations on publish so the database schema is updated in Azure SQL.
And tadah! The app is running in Azure and using Azure SQL for data storage :)
Check the official documentation for more information.