dev.azure_在Azure中将我的播客站点升级到ASP.NET Core 2.1以及一些最佳实践

dev.azure

dev.azure

I am continuing to upgrade to podcast's site. Today I upgraded it to .NET Core 2.1, keeping the work going from my upgrade from "Web Matrix WebPages" from last week. I upgraded to actually running ASP.NET Core 2.1's preview in Azure by following this blog post.

我正在继续升级到播客的网站。 今天,我将其升级到.NET Core 2.1从上周开始从“ Web Matrix WebPages”升级就保持了工作通过关注此博客文章,我已升级为在Azure中实际运行ASP.NET Core 2.1的预览

Pro Tip: Be aware, you can still get up to 10x faster local builds but still keep your site's runtime as 2.0 to lower risk. So there's little reason to not download the .NET Core 2.1 Preview and test your build speeds.

专家提示:请注意,您仍然可以将本地构建速度提高10倍,但仍将站点的运行时保持为2.0,以降低风险。 因此,没有理由不下载.NET Core 2.1预览版并测试构建速度。

At this point the podcast site is live in Azure at https://hanselminutes.com. Now that I've moved off of the (very old) site I've quickly set up some best practices in just a few hours. I should have taken the time to upgrade this site - and its "devops" a long time ago.

此时,播客站点位于https://hanselminutes.com上的Azure中。 现在,我已经离开了(很旧的)网站,我在短短几个小时内就Swift建立了一些最佳实践。 我应该花时间升级这个网站-很久以前,它的“发展”。

Here's a few things I was able to get done just this evening while the boys' did homework. Each of these tasks were between 5 and 15 min. So not a big investment, but they represented real value I'd been wanting to add to the site.

这是我今晚在男孩们做作业时能够完成的几件事。 这些任务中的每一个都在5到15分钟之间。 因此,这不是一笔大投资,但它们代表了我一直想添加到网站上的真实价值。

Git部署生产 (Git Deploy for Production )

The podcast site's code now lives in GitHub and deployment to production is a git push to master.

现在,该播客站点的代码位于GitHub中,并且将其部署到生产环境是掌握的一个git push。

Deploying from GitHub

一个用于阶段的“部署槽” (A "deployment slot" for staging)

Some people like to have the master branch be Production, then they make a branch called Staging for a secondary staging site. Since Azure App Services (WebSites) has "deployment slots" I choose to do it differently. I deploy to Production from GitHub, sure, but I prefer to push manually to staging rather than litter my commits (and clean them up or squash commits later - it's just my preference) with little stuff.

有些人喜欢将主分支设为Production,然后他们为辅助登台站点创建了一个名为Staging的分支。 由于Azure App Services(WebSites)具有“部署槽”,因此我选择以不同的方式进行。 当然,我是从GitHub部署到Production的,但是我宁愿手动推送到暂存阶段,而不要乱扔我的提交(稍后清理或压缩提交-这只是我的偏爱)而已。

I hooked up Git Deployment but the git repro is in Azure and just for deploy. Then "git remote add azure ..." so when I want to deploy to staging it's:

我连接了Git部署,但是git repro在Azure中,仅用于部署。 然后“ git remote add azure ...”,所以当我想部署到舞台上时:

git push staging

I use it for testing, so ya, it could have been test/dev, etc, but you get the idea. Plus the Deployment Slot/Staging Site is free as it's on the same Azure App Service Plan.

我将其用于测试,所以,它可能是test / dev等,但是您明白了。 另外,部署槽/登台站点是免费的,因为它在同一Azure应用服务计划中。

A more sophisticated - but just as easy - plan would be to push to staging, get it perfect then do a "hot swap" with a single button click.

一个更复杂但又同样容易的计划是推动分期,使其完美,然后单击一次按钮即可进行“热插拔”。

Deployment Slots can have their own independent settings if you click "Slot Setting." Here I've set that this ASPNETCORE_ENVIRONMENT is "Staging" while the main one is "Production."

如果单击“插槽设置”,则部署插槽可以具有自己的独立设置。 在这里,我将ASPNETCORE_ENVIRONMENT设置为“暂存”,而主要的是“生产”。

Staging Slots in Azure

The ASP.NET Core runtime picks up that environment variable and I can conditionally run code based on Environment. I run as "Development" on my local machine. For example:

ASP.NET Core运行时获取该环境变量,我可以有条件地基于Environment运行代码。 我在本地计算机上以“开发”身份运行。 例如:

if (env.IsDevelopment()){
    app.UseDeveloperExceptionPage();
}
else{
    app.UseExceptionHandler("/Error");
}

不要让Google将登台网站编入索引-没有机器人 (Don't let Google Index the Staging Site - No Robots)

You should be careful to not let Google/Bing/DuckDuckGo index your staging site if it's public. Since I have an environment set on my slot, I can just add this Meta Robots element to the site's main layout. Note also that I use minified CSS when I'm not in Development.

您应该小心,不要让Google / Bing / DuckDuckGo为您的登台网站建立索引。 由于我在自己的广告位上设置了环境,因此我可以将此Meta Robots元素添加到网站的主布局中。 另请注意,不在开发环境中时,我会使用缩小CSS。

<environment include="Development">
    <link rel="stylesheet" href="~/css/site.css" />
</environment>
<environment exclude="Development">
    <link rel="stylesheet" href="~/css/site.min.css" />
</environment>
<environment include="Staging">
    <meta name="robots" content="noindex, follow">
</environment>

需要SSL (Require SSL )

Making the whole ASP.NET Core site use SSL has been on my list as well. I added my SSL Certs in the Azure Portal that added RequreHttps in my Startup.cs pretty easily.

使整个ASP.NET Core网站都使用SSL也在我的清单上。 我在Azure门户中添加了SSL证书,该证书很容易在Startup.cs中添加了RequreHttps。

I could have also added it to the existing IISRewriteUrls.xml legacy file, but this was easier and faster.

我也可以将其添加到现有的IISRewriteUrls.xml旧文件中,但这更方便快捷。

var options = new RewriteOptions().AddRedirectToHttps();

Here's how I'd do via IIS Rewrite Middleware, FYI:

这是我通过IIS重写中间件(FYI)进行的操作:

<rule name="HTTP to HTTPS redirect" stopProcessing="true">
    <match url="(.*)" />
    <conditions>
       <add input="{HTTPS}" pattern="off" ignoreCase="true" />
    </conditions>
    <action type="Redirect" url="https://{HTTP_HOST}/{R:1}"
redirectType="Permanent" />
</rule>

ASP.NET Core的应用程序见解(Application Insights for ASP.NET Core)

Next post I'll talk about Application Insights. I was able to set it up both client- and server-side and get a TON of info in about 15 minutes.

下一篇文章,我将讨论Application Insights。 我能够在客户端和服务器端进行设置,并在大约15分钟内获得大量信息。

Application Insights

How are you?

你好吗?

Sponsor: Unleash a faster Python! Supercharge your applications performance on future forward Intel platforms with The Intel Distribution for Python. Available for Windows, Linux, and macOS. Get the Intel® Distribution for Python Now!

赞助者:释放更快的Python! 借助适用于Python的英特尔发行版,在未来的未来英特尔平台上增强您的应用程序性能。 适用于Windows,Linux和macOS。 立即获取适用于Python的英特尔®发行版!

翻译自: https://www.hanselman.com/blog/upgrading-my-podcast-site-to-aspnet-core-21-in-azure-plus-some-best-practices

dev.azure

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值