Create an ASP.NET web app in Azure App Service

资料来源:https://azure.microsoft.com/en-us/documentation/articles/web-sites-dotnet-get-started/


Overview

This tutorial shows how to deploy an ASP.NET web application to a web app in Azure App Service by using Visual Studio 2015 or Visual Studio 2013. The tutorial assumes that you are an ASP.NET developer who has no prior experience with using Azure. On completing the tutorial, you'll have a simple web application up and running in the cloud.

The following illustration shows the completed application:

Web app home page

You'll learn:

  • How to prepare your machine for Azure development by installing the Azure SDK for .NET.
  • How to set up Visual Studio to create a new App Service web app while it creates an ASP.NET MVC 5 web project.
  • How to deploy a web project to an App Service web app by using Visual Studio.
  • How to use Visual Studio Server Explorer to open remote files and start a remote debug session.
  • How to use the Azure portal to monitor and manage your web app.

Sign up for Microsoft Azure

You need an Azure account to complete this tutorial. You can:

  • Open an Azure account for free. You get credits that can be used to try out paid Azure services. Even after the credits are used up, you can keep the account and use free Azure services and features, such as the Web Apps feature in Azure App Service.
  • Activate MSDN subscriber benefits. Your MSDN subscription gives you credits every month that you can use for paid Azure services.

If you want to get started with Azure App Service before you sign up for an Azure account, go to Try App Service. There, you can immediately create a short-lived starter web app in App Service—no credit card required, and no commitments.

In the following video, Scott Hanselman shows how easy it is to sign up for a free trial of Microsoft Azure. (Duration: 1:58)

Set up the development environment

To start, set up your development environment by installing the Azure SDK for Visual Studio 2015 or the Azure SDK for Visual Studio 2013.

If you don't have Visual Studio installed, use the link for Visual Studio 2015, and Visual Studio will be installed along with the SDK.

Create a project and a web app

Your first step is to create a web project in Visual Studio and a web app in Azure App Service. When that's done, you'll deploy the project to the web app to make it available on the Internet.

The diagram illustrates what you're doing in the create and deploy steps.

Create and deploy

  1. Open Visual Studio 2015 or Visual Studio 2013.

    If you use Visual Studio 2013, the screens will be slightly different from the screenshots, but the procedures are essentially the same.

  2. From the File menu, click New > Project.

  3. In the New Project dialog box, click C# > Web > ASP.NET Web Application. If you prefer, you can choose Visual Basic.

  4. Make sure that .NET Framework 4.5.2 is selected as the target framework.

  5. Azure Application Insights monitors your web app for availability, performance, and usage. Clear the Add Application Insights to Project check box if you don't want to try it.

  6. Name the application MyExample.

  7. Click OK.

    New Project dialog box

  8. In the New ASP.NET Project dialog box, select the MVC template.

    MVC is an ASP.NET framework for developing web apps.

  9. Click Change Authentication.

    New ASP.NET Project dialog box

  10. In the Change Authentication dialog box, click No Authentication, and then click OK.

    No Authentication

    The sample application that you're creating won't enable users to log in. The Next steps section links to a tutorial that implements authentication and authorization.

  11. In the New ASP.NET Project dialog box, leave the settings under Microsoft Azure unchanged, and then click OK.

    New ASP.NET Project dialog box

    The default settings specify that Visual Studio will create an Azure web app for your web project. In the next section of the tutorial, you'll deploy the web project to the newly created web app.

  12. If you haven't already signed in to Azure, Visual Studio prompts you to do so. Sign in with the ID and password of the account that you use to manage your Azure subscription.

    When you're signed in, the Configure Microsoft Azure Web App Settings dialog box asks you what resources you want to create.

    Signed in to Azure

  13. In the Configure Microsoft Azure Web App Settings dialog box, enter a Web App name that is unique in theazurewebsites.net domain. For example, you can name it MyExample with numbers to the right to make it unique, such as MyExample810. If a default web name is created for you, it will be unique and you can use that.

    If someone else has already used the name that you enter, you'll see a red exclamation mark to the right instead of a green check mark, and you'll need to enter a different name.

    Azure will use this name as the prefix for your application's URL. The complete URL will consist of this name plus.azurewebsites.net (as shown next to the Web App name text box). For example, if the name is MyExample810, the URL will be MyExample810.azurewebsites.net. The URL has to be unique.

  14. In the App Service plan drop-down, select Create new App Service plan.

    The Next steps section has links to information about App Service plans.

  15. Enter MyExamplePlan, or another name if you prefer, for the plan name.

  16. In the Resource group drop-down, select Create new resource group.

    The Next steps section has links to information about resource groups.

  17. Enter MyExampleGroup, or another name if you prefer, for the resource group name.

  18. In the Region drop-down list, choose the location that is closest to you.

    This setting specifies which Azure datacenter your web app will run in. For this tutorial, you can select any region and it won't make a noticeable difference. But for a production web app, you want your web server to be as close as possible to the browsers that are accessing your site in order to minimize latency.

  19. Leave the database field unchanged.

    For this tutorial, you aren't using a database. The Next steps section links to a tutorial that shows how to use a database.

  20. Click OK.

    In a few seconds, Visual Studio creates the web project in the folder that you specified, and it creates the web app in the Azure region that you specified.

    The Solution Explorer window shows the files and folders in the new project.

    Solution Explorer

    The Azure App Service Activity window shows that the web app has been created.

    Web app created

    And you can see the web app in Server Explorer.

    Web app created

Deploy the project to the web app

In this section you deploy web project to the web app, as illustrated in step 2 of the diagram.

Create and deploy

  1. In Solution Explorer, right-click the project, and choose Publish.

    Choose Publish

    In a few seconds, the Publish Web wizard appears. The wizard opens to a publish profile that has settings for deploying the web project to the new web app. If you wanted to deploy to a different web app, you could click the Profile tab to create a different profile. For this tutorial, you'll accept the settings that deploy to the web app that you created earlier.

  2. On the Connection tab of the Publish Web wizard, click Next.

    Successfully validated connection

  3. On the Settings tab, click Next.

    You can accept the default values for Configuration and File Publish Options.

    You can use the Configuration drop-down to deploy a Debug build for remote debugging. The Next steps section links to a tutorial that shows how to run Visual Studio in debug mode remotely.

    Settings tab

  4. On the Preview tab, click Publish.

    If you want to see what files will be copied to Azure, you can click Start Preview before clicking Publish.

    When you click Publish Visual Studio begins the process of copying the files to the Azure server.

    The Output and Azure App Service Activity windows show what deployment actions were taken and report successful completion of the deployment.

    Output window reporting successful deployment

    Upon successful deployment, the default browser automatically opens to the URL of the deployed web app, and the application that you created is now running in the cloud. The URL in the browser address bar shows that the web app is loaded from the Internet.

    Web app running in Azure

  5. Keep this browser window open for use in the next section.

Tip: You can enable the Web One Click Publish toolbar for quick deployment. Click View > Toolbars, and then select Web One Click Publish. You can use the toolbar to select a profile, click a button to publish, or click a button to open the Publish Web wizard.

Web One Click Publish Toolbar

Open remote files in Server Explorer

When you're testing and debugging a web app, you can do quick temporary changes on the remote site by opening and editing files in Server Explorer.

  1. In Server Explorer, navigate to Azure > App Service > MyExampleGroup, and then expand the node for your web app.

  2. Expand Files > Views > Home, and then double-click the Index.cshtml file.

  3. Change <h1>ASP.NET</h1> to <h1>Azure App Service</h1>.

  4. Save the file.

  5. Refresh the browser window that has the site running in Azure.

This change is now in the deployed site but not the local project. If you redeploy the project, the site will revert to the way it was before you made this change.

This feature is handy for temporarily turning off customErrors in the Web.config file in order to get a detailed error message.

In Server Explorer you can also right-click the web app node and get access to web app settings in a Visual Studio window, start a remote debugging session, and view application logs in real time as the application writes them.

For more information, see Troubleshooting Azure web apps in Visual Studio.

Monitor and manage the web app in the Azure portal

The Azure portal is a web interface that you can use to manage and monitor your Azure services, such as the web app that you just created. In this section of the tutorial, you look at some of what you can do in the portal.

  1. In your browser, go to https://portal.azure.com, and sign in with your Azure credentials.

  2. Click Web Apps, and then click the name of your web app.

    The Web app blade displays an overview of settings and usage statistics for your web app.

    Web app blade

    At this point, your web app hasn't had much traffic and may not show anything in the graph. If you browse to your application, refresh the page a few times, and then refresh the portal page, you'll see some statistics show up.

  3. Click Settings to see more options for configuring your web app.

    Click Settings

    You see a list of types of settings.

  4. Click Application settings to see an example of the kinds of settings that you can configure in the portal.

    For example, you can control the .NET version that's used for the web app, enable features such as WebSockets, and setconnection string values.

    Portal web app configure tab

These are just a few of the portal's features. You can create new web apps, delete existing web apps, stop and restart web apps, and manage other kinds of Azure services, such as databases and virtual machines.

Next steps

In this tutorial, you've seen how to create a simple web application and deploy it to an Azure web app. Here are some related topics and resources for learning more about web apps in Azure App Service:

What's changed


  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值