Azure to deploy asp.net website

Azure to deploy asp.net website

 

Foreword

A few days ago have been writing a single page of the web application, finally completed, then consider publishing to the cloud server. I did not AWS account, then planned to use Google cloud. After finding a way to reference the document official document given to use on Studio Visual Cloud Tools for Visual Studio plug-in, but the plug-in appears to only support vs2017, but can only switch to Azure. I will continue to follow-up free time to explore the deployment of ASP.NET applications on Google, after all, only to Azure a month, a year of free time to enjoy only after the upgrade account.

 

let us start

 This is the first use of white, so just my own method and order, for reference purposes only. If you have a big brother more convenient way to welcome, if imperfect error also please point out. Thank you!

 

build database

First, we need to create a database on Azure. This process made reference to this article .

 

After opening the first page of search Azure sql database, sql database and select Go.

 

 

 

Then we add a database. I've got a database instance which, if not interface could and I are not the same.

 

 

 

Probably long after the open like this:

 

 

 

 From top to bottom fill in the information.

* Subscriptions: If an account is free seems the only option, forgive me for not seen long-sawed paid account.

* Resource Group: If you have previously been established, the resource group created before you can select or create a new resource group. If you do not you will only create a new up. You can play your favorite name when a New.

* Database name: You can play your favorite a name, we can not have had before.

* Server: If you have previously been established, or create a new one before you can choose. If you do not create a new one. It will be displayed on the right after click New:

 

  * Server name: This is equivalent to the domain name of your database server, it must be unique

  * Server administrator login: Account name database administrator, after logging database at the time of connection and use it as a management user name.

  * Password: password database, with the former, respectively.

  * 位置:服务器所在位置。我选择了距离我最近的位置,大家可以按需自行选择。(虽然是离我最近的位置但是访问速度依然不快)

  * 允许 Azure 服务访问服务器:这个一定要选上,以允许你的网站使用建立的数据库服务器。

* 想要使用 SQL 弹性池:这个我用不上,大家可以自行按需选择。

* 计算 + 存储:这个可以用来配置数据库的大小,大家可以按需进行调整。打开以后是这个样子的:

一般情况下就可以点击左下的 查看 + 创建 来建库了。

 

 

 如果还有其他需求可以点 Next: 其他设置> 进行设置。

然后等配置完成,在 sql 数据库 界面就出现了刚刚建立的数据库了。

 

 

点击名称,可以转到详细信息页面:

 

 

右上方的服务器名称就是待会用来连接数据库的服务器名称。

点击连接字符串可以显示数据库连接字符串格式,使用时需要手动替换掉数据库管理员用户名和密码。

 

 

 

 

ASP.NET 项目连接数据库

使用刚刚的数据库连接字符串,替代你的项目里的数据库连接字符串,providerName 依然可以使用 System.Data.SqlClient。此时你的项目已经在使用你在Azure上的数据库了。

然而,现在这个数据库还是空的,需要建表,而且现在也不能方便的管理数据库。此时需要在 visual studio 上或 Microsoft SQL Server Management Studio 上连接数据库进行管理。

 

在visual studio上连接远端数据库

此处以 visual studio 2019 为例。点击服务器资源管理器上的添加按钮来新建一个连接:

 

 

点击 Azure, 登录你的Azure账号,下面会显示出来你的账号中的数据库实例。

 

 

选择你想连接的数据库,服务器名称即在数据库详情里看到的服务器名称,身份验证选择 SQL Server身份验证,用户名和密码就是建立数据库的时候配置的数据库管理员账户和密码(和连接字符串里替换的那个一样)。然后连接即可。

接下来即可对数据库进行管理,建表什么的,然后就可以使用了。

 

在Microsoft SQL Server Management Studio上连接远端数据库

下面是以 Microsoft SQL Server Management Studio 19 为例的演示,其他版本大同小异。

 

打开 Microsoft SQL Server Management Studio 19,出现 连接到服务器 对话框。

 

* 服务器类型:选择 数据库引擎

* 服务器名称:就是熟悉的那个服务器名称,Azure 数据库详细页面里那个。

* 身份验证:选择 SQL Server 身份验证

* 登录名:这里需要注意,需要填写 你的数据库管理员用户名@服务器名称,不能只填写管理员用户名。

* 密码:嗯,就是那个密码。

然后连接,就可以了。

 

发布网站

折腾好数据库结构后就可以发布网站了(还没有在数据库建表的话现在快去建表)。如果你希望直接迁移数据库的话,可以直接在visual studio中使用数据库迁移。由于我不想把测试时的乱七八糟的数据上传,所有没有用。如需要请自行搜索吧,参考的那篇文章里也有一些说明。发布的步骤参考了微软官方文档

 

首先要确保你所有的资源都已经包含在项目内了,否则发布后会出现找不到资源的情况。在本地测试时可能路径在同一个文件夹中不会出现错误,但是发布到远端时,没有包含在项目中的资源是不会被上传到服务器的,这里需要注意。

解决方案web项目上 右键 > 发布(在类库上右键是没有发布的)。

 

 

选择第一个应用服务。可以选择新建或现有的。此处选择新建:

 

 

 点击发布后会让你登录Azure账户(已经登录的可以省去此步骤)。之后会出现一些应用的设置:

 

 

 可以起一个响亮的名字,资源组选择你要发布到的资源组,其他按(bao)需(chi)选(mo)择(ren),然后点击创建。

稍候,vs会在发布成功后自动在浏览器中打开发布的网页。以后都可以登录这个URL进行访问啦!

在 Azure 的所有资源中可以看到所有的资源。不只是刚刚发布的网站,而且包括其他时候发布到各个资源组里的各种东西。我这里只有这一个项目。

 

 

总结 

微软的全家桶服务让网站的开发维护和发布变得很简单顺畅,过程并不难。要是Azure的免费时间给的再宽泛一些就更好了。

 

最后祝大家中秋快乐!

Guess you like

Origin www.cnblogs.com/JamSun/p/11519160.html