Learn how to create an ASP.NET application with Visual Studio and then publish that application to Azure.
- [Instructor] To see this alternative approach, let's open up Visual Studio, and for this, you can use any version of Visual Studio, preferably 2017. That can be the community edition, the enterprise edition, or whatever else you're working with. When you first start up Visual Studio, you're going to need to sign in. Once again, I'm going to use my Microsoft account, so let me put in the email, and it's going to redirect me over to the Microsoft sign in page, and here I can put in the password.
This will only happen the first time you're using Visual Studio. It has found my account and it's going to set up Visual Studio, in this case, based on the default configuration. Now that Visual Studio is open, we're ready to create our ASP.NET web application. We're going to say file, new, project. The templates come up.
The one that we want is web. And within that, we're going to want the ASP.NET web application .NET framework. You can use .NET core, but let's keep things simple. And here we're going to create a new application. Let's call this application jl-WebApplication2. We'll let it create a directory for the solution and put it into our favorite location for our files, you can set that to anything you like.
And we'll click OK. We're going to make this a simple MVC application, and we're going to leave authentication set to no authentication. We'll be looking at authentication in an upcoming video, but for now, no authentication is just fine. And we'll click OK. Visual Studio is going to create the project. That can take a few minutes. Once it comes up, we have a starter application. We can run that starter application by clicking on the browser of choice.
Browser will open. And we can see that our starter application is in place. Notice the URL says localhost and then a port. Your port number, of course, may be different from this one. But what's important here is it's running locally. If we go to the about menu choice, we see the default about page. The next step is we want to deploy this to Azure.
Let's go back to home and minimize or, actually, close this version, return us to Visual Studio, and on the left, we're going to click publish, which will start the procedure for publishing this to Azure. We want first to pick our app service target, in this case, Microsoft Azure App Services, and we're going to say that we're creating a new one.
When we click the publish button, the create app services dialogue will come up. It's going to offer us what it believes to be a unique app name, and of course, this would be unique, but it's a little more complicated than we need. We can pare this down, as long as what we end up with is unique, and in this case, it will be, jl-WebApplication2. We need to pick our subscription, I don't want to use pay-as-I-go. Instead, use my MSDN subscription.
And it's going to say what resource group would you like. I'm going to choose a new resource group and put in a new name, or, I can leave the resource group that I have, which is the one that we established earlier. We can drop that down and see if there are any others in place. Next, we come up with an app service plan. Once again, I can click on new app service plan.
Let's go ahead and do that and say that this is going to be jl-WebApplication2Plan. Simplify the name they provided. For location, I'm going to choose West US. And for size, once again, we get into the service plan size. In this case, I'm going to choose the basic plan, B1. And click OK. When we look at the hosting now, each of those choices is in place and we're ready to go ahead and create.
Visual Studio is now going to deploy this application to Azure. And this, too, can take a few minutes. Once this has been deployed, we will open up the browser, and notice the URL now is no longer local host, but is, in fact, on azurewebsites.net. So what we're seeing, as soon as this comes up, is our application running on Azure.
And here we have our starter application on Azure. I'm going to go back to that about box, and note that it's the same as it was on local. But let's modify that by going back to Visual Studio. We return to Visual Studio and we're going to go down to the view. And within views, we're going to go to home, where we find the CSHTML files for the about box and the contacts and so forth.
Let's double-click on about. And here we have the about box that we saw. Let's just add something to indicate that we're making a change, so we'll add an H2 header and put in some random text. I made a change. Save that and we're ready to re-deploy that to Azure. To do so, go back to your main page, click publish, and this time, it's going to be much quicker.
Up comes the browser. You can see by looking at the URL that we are looking at the deployed application, and if we go to the about box, the change we made locally in Visual Studio has been deployed to Azure.
- Examining and personalizing the Azure portal
- Creating an app service
- Creating an ASP.NET application with Visual Studio
- Viewing your published app
- Creating a virtual machine
- Triggering Azure functions