【翻译】使用Visual Studio在Azure上部署Asp.Net Core Web应用

简介: 配置运行环境 Install the latest Azure SDK for Visual Studio. The SDK installs Visual Studio if you don't already have it.

配置运行环境

创建Web应用

In the Visual Studio Start Page, tap New Project....

在Visual Studio启示页面,点击New Project…

img_8a0bd543f4ebef2d461074bb631de839.png

Alternatively, you can use the menus to create a new project. Tap File > New > Project....

你也可以通过菜单来创建一个新的项目。点击File > New > Project…

img_631cbd9b041612c51778e66b8cd5ab36.png

Complete the New Project dialog:

完成新项目的创建

  • In the left pane, tap Web

  • 在左边面板,点击Web

  • In the center pane, tap ASP.NET Core Web Application (.NET Core)

  • 在中间的面板,点击选择Asp.Net Core Web Application(.Net Core)

  • Tap OK

  • 点击OK

img_6c80ee45da575681603ed518457775b7.png

In the New ASP.NET Core Web Application (.NET Core) dialog:

在New Asp.Net Core Web Application(.Net Core)对话框中:

  • Tap Web Application

  • 点击Web Application

  • Verify Authentication is set to Individual User Accounts

  • Authentication设置成Individual User Accounts

  • Verify Host in the cloud is not checked

  • 不选中Host in the Cloud

  • Tap OK

  • 点击OK

在本地测试应用

  • Press Ctrl-F5 to run the app locally

  • 按Ctrl+F5在本地运行应用

  • Tap the About and Contact links. Depending on the size of your device, you might need to tap the navigation icon to show the links

  • 点击About和Contact链接,根据你设备分辨率的大小,你可能需要点击导航图标才能看到这些链接。

img_ab43d66160b98ea53083f70aacc7bbe5.png

  • Tap Register and register a new user. You can use a fictitious email address. When you submit, you'll get the following error:
  • 点击注册链接注册一个新的用户。你可以输入虚拟的Email地址,当你点击提交的时候,你会看到错误:

img_81f3f251416d072dd3b7ee57474d28c3.png

You can fix the problem in two different ways:

你可以使用以下两种方式修复问题:

  • Tap Apply Migrations and, once the page updates, refresh the page;

  • 点击Apply Migrations,等待更新后,刷新页面

  • Run the following from a command prompt in the project's directory:

  • 在命令终端下,到项目目录运行以下命令:

dotnet ef database update

The app displays the email used to register the new user and a Log off link.

刷新页面后,页面会显示我们注册的新用户和看到一个Log off的链接。

img_318dc4edf215e552d48c8b4f6b0edb06.png

应用部署到Azure

Right-click on the project in Solution Explorer and select Publish....

在Solution Explorer右键项目,点击Publish

img_3d8db3e0f4b765b3772d1fb95e85431b.png

In the Publish dialog, tap Microsoft Azure App Service.

在Publish对话框中,点击Microsoft Azure App service.

Tap New... to create a new resource group. Creating a new resource group will make it easier to delete all the Azure resources you create in this tutorial.

点击New创建一个新的资源组。创建新的资源组可以方便你删除所有在Azure上创建的范例资源。

img_6f547348653555f8fea1bf4955eb94a5.png

Create a new resource group and app service plan:

添加一个新的Resource group和app service plan:

  • Tap New... for the resource group and enter a name for the new resource group

  • 在resource group点击New,然后为这个资源组取名

  • Tap New... for the app service plan and select a location near you. You can keep the default generated name

  • 在app service plan点击New,选择一个

  • Tap Explore additional Azure services to create a new database

  • 点击Explore additional Azure services去创建一个新的数据库

img_78cd2e4fb1faa88158e7df5b64d049c1.png

  • Tap the green + icon to create a new SQL Database
  • 点击绿色的加号图标创建一个新的Sql数据库

img_bbb4356ab102c5e7325cbfd7f60e9613.png

  • Tap New... on the Configure SQL Database dialog to create a new database server.
  • 在Configure Sql Database对话框中点击New创建一个新的数据库

img_8a87f4656e8e852a4d107f910796e967.png

  • Enter an administrator user name and password, and then tap OK. Don't forget the user name and password you create in this step. You can keep the default Server Name
  • 输入一个管理员名和密码,点击OK。不要忘记你设置的用户名和密码。ServerName可以保持默认的。

img_f20a4cde1694cb3f7db26645b0d63581.png

  • Tap OK on the Configure SQL Database dialog
  • 在Configure SQL Database对话框点击OK

img_6e9abe6469680bcfeaa673dca2436979.png

  • Tap Create on the Create App Service dialog
  • 在Creat App Service对话框点击Create

img_034a16afea0027af249323296421a677.png

  • Tap Next in the Publish dialog
  • 在Publish对话框点击Next

img_c9ed87ccde5e2f7f15a18dab83b4aa93.png

  • On the Settings stage of the Publish dialog:

  • 点击Publish对话框的Settings标签

    • Expand Databases and check Use this connection string at runtime

    • 扩展Databases,选中Use this connection string at runtime

    • Expand Entity Framework Migrations and check Apply this migration on publish

    • 扩展Entity Framework Migrations,选中Apply this migration on publish

  • Tap Publish and wait until Visual Studio finishes publishing your app

  • 点击Publish,等待Visual Studio完成发布你的应用。

img_f6080e3a183a7cc91ac400243571554c.png

Visual Studio will publish your app to Azure and launch the cloud app in your browser.

Visual Studio会在发布到Azure后通过浏览器打开你在云端部署的应用。

在Azure上测试你的应用

  • Test the About and Contact links

  • 测试About和Contact链接

  • Register a new user

  • 注册一个用户

img_789434276211d988c089ebc29d4643e1.png

更新应用

  • Edit the Views/Home/About.cshtml Razor view file and change its contents. For example:
  • 编辑Views/Home/About.cshtml文件,修改它。参考:
@{
       ViewData["Title"] = "About";
   }
   <h2>@ViewData["Title"].</h2>
   <h3>@ViewData["Message"]</h3>

   <p>My updated about page.</p>
  • Right-click on the project and tap Publish... again
  • 再次右键项目点击Publish

img_3d8db3e0f4b765b3772d1fb95e85431b.png

  • After the app is published, verify the changes you made are available on Azure
  • 发布后,检查下在Azure端的应用是否改变

清除应用

When you have finished testing the app, go to the Azure portal and delete the app.

当你完成测试后,去Azure后台删除这个应用。

  • Select Resource groups, then tap the resource group you created
  • 选择Resource groups,然后选中你创建的资源组

img_25a21c7c53f4125c7e5a46b3b1498bee.png

  • In the Resource group blade, tap Delete
  • 在Resource group选项卡中,点击Delete

img_7c5673f927251320818542d9ba775b23.png

  • Enter the name of the resource group and tap Delete. Your app and all other resources created in this tutorial are now deleted from Azure
  • 输入资源组名点击Delete。你的应用和创建的资源在Azure中将会被删除。

原文链接

https://docs.microsoft.com/zh-cn/aspnet/core/tutorials/publish-to-azure-webapp-using-vs

相关文章
|
2月前
|
开发框架 .NET 开发者
简化 ASP.NET Core 依赖注入(DI)注册-Scrutor
Scrutor 是一个简化 ASP.NET Core 应用程序中依赖注入(DI)注册过程的开源库,支持自动扫描和注册服务。通过简单的配置,开发者可以轻松地从指定程序集中筛选、注册服务,并设置其生命周期,同时支持服务装饰等高级功能。适用于大型项目,提高代码的可维护性和简洁性。仓库地址:&lt;https://github.com/khellang/Scrutor&gt;
73 5
|
2月前
|
开发框架 前端开发 JavaScript
ASP.NET Web Pages - 教程
ASP.NET Web Pages 是一种用于创建动态网页的开发模式,采用HTML、CSS、JavaScript 和服务器脚本。本教程聚焦于Web Pages,介绍如何使用Razor语法结合服务器端代码与前端技术,以及利用WebMatrix工具进行开发。适合初学者入门ASP.NET。
|
3天前
|
中间件 关系型数据库 数据库
docker快速部署OS web中间件 数据库 编程应用
通过Docker,可以轻松地部署操作系统、Web中间件、数据库和编程应用。本文详细介绍了使用Docker部署这些组件的基本步骤和命令,展示了如何通过Docker Compose编排多容器应用。希望本文能帮助开发者更高效地使用Docker进行应用部署和管理。
33 19
|
1月前
|
Web App开发 编解码 vr&ar
使用Web浏览器访问UE应用的最佳实践
在3D/XR应用开发中,尤其是基于UE(虚幻引擎)开发的高精度场景,传统终端因硬件局限难以流畅运行高帧率、复杂效果的三维应用。实时云渲染技术,将渲染任务转移至云端服务器,降低终端硬件要求,确保用户获得流畅体验。具备弹性扩展、优化传输协议、跨平台支持和安全性等优势,适用于多种终端和场景,特别集成像素流送技术,帮助UE开发者实现低代码上云操作,简化部署流程,保留UE引擎的强大开发能力,确保画面精美且终端轻量化。
104 17
使用Web浏览器访问UE应用的最佳实践
|
1月前
|
开发框架 数据可视化 .NET
.NET 中管理 Web API 文档的两种方式
.NET 中管理 Web API 文档的两种方式
48 14
|
2月前
|
运维 前端开发 C#
一套以用户体验出发的.NET8 Web开源框架
一套以用户体验出发的.NET8 Web开源框架
一套以用户体验出发的.NET8 Web开源框架
|
2月前
|
弹性计算 Java 关系型数据库
Web应用上云经典架构实践教学
Web应用上云经典架构实践教学
Web应用上云经典架构实践教学
|
2月前
|
Kubernetes 安全 Devops
有效抵御网络应用及API威胁,聊聊F5 BIG-IP Next Web应用防火墙
有效抵御网络应用及API威胁,聊聊F5 BIG-IP Next Web应用防火墙
100 10
有效抵御网络应用及API威胁,聊聊F5 BIG-IP Next Web应用防火墙
|
2月前
|
开发框架 算法 中间件
ASP.NET Core 中的速率限制中间件
在ASP.NET Core中,速率限制中间件用于控制客户端请求速率,防止服务器过载并提高安全性。通过`AddRateLimiter`注册服务,并配置不同策略如固定窗口、滑动窗口、令牌桶和并发限制。这些策略可在全局、控制器或动作级别应用,支持自定义响应处理。使用中间件`UseRateLimiter`启用限流功能,并可通过属性禁用特定控制器或动作的限流。这有助于有效保护API免受滥用和过载。 欢迎关注我的公众号:Net分享 (239字符)
68 1
|
3月前
|
开发框架 .NET C#
在 ASP.NET Core 中创建 gRPC 客户端和服务器
本文介绍了如何使用 gRPC 框架搭建一个简单的“Hello World”示例。首先创建了一个名为 GrpcDemo 的解决方案,其中包含一个 gRPC 服务端项目 GrpcServer 和一个客户端项目 GrpcClient。服务端通过定义 `greeter.proto` 文件中的服务和消息类型,实现了一个简单的问候服务 `GreeterService`。客户端则通过 gRPC 客户端库连接到服务端并调用其 `SayHello` 方法,展示了 gRPC 在 C# 中的基本使用方法。
70 5
在 ASP.NET Core 中创建 gRPC 客户端和服务器

热门文章

最新文章