简体   繁体   English

将 Web 应用程序 + sql db + windows 服务部署到 Azure

[英]Deploying a web app + sql db + windows service to Azure

I've never deployed to azure and I have several issues trying to get this to work.我从来没有部署到 azure,我在尝试让它工作时遇到了几个问题。 Im using the free services with azure.我正在使用 azure 的免费服务。

I have an mvc web app that's a custom calendar i made, a personal project of mine.我有一个 mvc web 应用程序,它是我制作的自定义日历,是我的个人项目。 The web app allows you to enter reminders and other kind of events to a local database i made. Web 应用程序允许您将提醒和其他类型的事件输入到我创建的本地数据库中。 Then theres a windows service I created to poll the database every minute to check if theres a reminder or similar event for that current time.然后我创建了一个 Windows 服务,每分钟轮询一次数据库,以检查当前时间是否有提醒或类似事件。 If there is the service emails that user the reminder and other details.如果有用户提醒和其他详细信息的服务电子邮件。 Locally everything works beautifully and i want to deploy to the web to show it off.在本地一切正常,我想部署到网络来炫耀它。

For me, deployment has been the issue.对我来说,部署一直是问题所在。 I've tried deploying the web app as a cloud service and web app + sql server.我尝试将 Web 应用程序部署为云服务和 Web 应用程序 + sql 服务器。 I then had problems with changing the connection strings in my web app to match azures.然后,我在更改 Web 应用程序中的连接字符串以匹配 azure 时遇到了问题。 So then I just tried to open the app itself and it took approx 30s per page to load.然后我只是尝试打开应用程序本身,加载每页大约需要 30 秒。 The VS solution has multiple projects because its a multi-tiered app (projects: database, DAL, BL, UI, Common). VS 解决方案有多个项目,因为它是一个多层应用程序(项目:数据库、DAL、BL、UI、Common)。

Then, I tried to add my version control code to the azure project which is in TFS.然后,我尝试将我的版本控制代码添加到 TFS 中的 azure 项目中。 I have like 4 projects i keep in source control but it only finds 1 in azure.我有 4 个项目,我保留在源代码管理中,但它只在 azure 中找到了 1 个。 I've researched this over and over and cant find anything on it.我一遍又一遍地研究了这个,但找不到任何关于它的东西。

I haven't even gotten to the windows service cause i can't get the app/db working together.我什至还没有进入 Windows 服务,因为我无法让应用程序/数据库协同工作。

TLDR; TLDR; The web app enters data into the database. Web 应用程序将数据输入到数据库中。 The service finds data entered and emails based on a matching date for each user.该服务根据每个用户的匹配日期查找输入的数据和电子邮件。 I'm doing deployment for the first time with azure and can't get the web app to connect to the database in azure to work properly, and the app is super slow when deployed.我是第一次用azure做部署,无法让web应用程序连接到azure中的数据库正常工作,部署时应用程序超级慢。

Main problems being TFS not showing all projects in azure, do i include all projects in solution or just the UI, getting connection strings to match azure.主要问题是 TFS 没有以 azure 显示所有项目,我是在解决方案中包含所有项目还是仅包含 UI,获取连接字符串以匹配 azure。 I'm a bit lost overall I guess... how can i get this all working?我想我总体上有点迷茫……我怎样才能让这一切正常工作?

When you say Web App I assume you mean Azure App Service ( https://azure.microsoft.com/en-us/services/app-service/ ).当您说 Web 应用程序时,我假设您指的是 Azure 应用程序服务 ( https://azure.microsoft.com/en-us/services/app-service/ )。

Setting an connectionstring for your App Service to use can be done in the portal by navigating to Application settings > Connection string under the resource.通过导航到资源下的应用程序设置 > 连接字符串,可以在门户中设置要使用的应用服务的连接字符串 It should be a regular connectionstring here, the only thing you need to do is make sure the server name is right and that you have a user and pwd set that will give you access to the database.这里应该是一个常规的连接字符串,您唯一需要做的就是确保服务器名称正确,并且您有一个用户和密码集,可以让您访问数据库。 If you created the resources using the Wep Abb (Web +SQL) in the portal then you entered a user and password for the database there, that will be fine for you to use in the connectionstring.如果您在门户中使用 Wep Abb (Web +SQL) 创建了资源,那么您在那里输入了数据库的用户名和密码,您可以在连接字符串中使用它。 You might want to add a dedicated user to the SQL server at a later stage and use that specifically for this application.您可能希望在稍后阶段将专用用户添加到 SQL 服务器,并将其专门用于此应用程序。

App Services has a built in feature that lets you deploy your code automatically from your source control.应用服务具有内置功能,可让您从源代码管理中自动部署代码。 You can set it up to build and deploy your MVC code to the App Service on commits to a specific branch in your repo.您可以将其设置为在提交到存储库中的特定分支时构建和部署您的 MVC 代码到应用服务。 Navigate to Deployment options under your App Service in the portal.导航到门户中应用服务下的部署选项 Here you set it up to target your TFS repo.在这里,您将其设置为针对您的 TFS 存储库。 Your problem might be that since you have 4 projects in your repo the build script wont know which one to build and deploy if all 4 are web projects.您的问题可能是,由于您的存储库中有 4 个项目,如果所有 4 个项目都是 Web 项目,则构建脚本将不知道要构建和部署哪一个。 If you need all 4 running then you need 4 App Services.如果您需要所有 4 个运行,那么您需要 4 个应用服务。 You can modify the script but it takes some work.您可以修改脚本,但这需要一些工作。 https://github.com/projectkudu/kudu/wiki/Custom-Deployment-Script https://github.com/projectkudu/kudu/wiki/Custom-Deployment-Script

Another option may be to setup Visual Studio Team Service to work for you using the Continuous Deploy feature (it's in preview but works fine).另一种选择可能是设置 Visual Studio Team Service 以使用持续部署功能为您工作(它处于预览状态,但工作正常)。

As for the continuously running service that should poll the database I recommend you look at Web Jobs to do that for you.至于应该轮询数据库的持续运行的服务,我建议您查看 Web Jobs 来为您执行此操作。 https://docs.microsoft.com/en-us/azure/app-service-web/websites-dotnet-webjobs-sdk-get-started . https://docs.microsoft.com/en-us/azure/app-service-web/websites-dotnet-webjobs-sdk-get-started The web jobs will run on the same App Service instance you run your site on. Web 作业将在您运行站点的同一应用服务实例上运行。

Last, in order to send emails from Azure you need to use an email service.最后,为了从 Azure 发送电子邮件,您需要使用电子邮件服务。 SendGrid is one that works well with Azure App Services and is easy enough to setup. SendGrid是一种适用于 Azure 应用服务且易于设置的工具。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM