我正在尝试实现Azure Web应用程序的零停机部署,其中数据库架构更新需要作为部署的一部分应用.
我有以下设置:
具有production-db连接字符串的生产 Web应用程序.
使用staging-db连接字符串暂存部署槽.
我的伪部署过程类似于:
换句话说,在热交换之后,我希望新代码和更新的数据库都是实时的.
如果此时出现问题,我可以再次交换插槽,使旧的生产应用程序(及其数据库)生效.
据我所知,当我交换插槽时,应用程序将使用生产槽的连接字符串,重新启动应用程序并强制我在更新的代码生效后应用数据库架构更新.
我希望我能正确地描述这一点.:)这似乎应该是一个相当常见的场景?
非常感谢任何帮助或指示!
PS.我在数据库架构更改时查看了Azure无缝升级,但该答案无效,因为我无法在不影响应用程序的情况下应用架构更新.
编辑:只是一个想法:也许我应该跳过将连接字符串作为门户设置,而只是将其保留在web.config中.这样,在交换时,应用程序将不需要重新启动,并且由于web.config将包含在交换中,新的生产槽将使用更新的数据库.
编辑2:我认为当应用程序设置或连接字符串在插槽之间不同时,我错误地认为应用程序重新启动.看来我确实可以为部署插槽设置不同的连接字符串(指向数据库副本),然后在没有重新启动的情况下进行交换,从而影响网站访问者.
基本上,我有一个具有以下方法的 API 控制器:
public void Post([FromBody] string value)
{
Repository.Save(value);
}
Run Code Online (Sandbox Code Playgroud)
我像这样构建我的表单:
@using (Ajax.BeginForm(new AjaxOptions { HttpMethod = "Post", Url = "/api/MyController"}))
{
<input type="text" name="value" value="" />
<input type="submit" value="Post" />
}
Run Code Online (Sandbox Code Playgroud)
请求被路由到控制器,但由于某种原因,该值始终为空。我试过使用和不使用 [FromBody] 属性。
我显然可以将值查询字符串参数附加到 URL,但我真的想弄清楚如何使用简单类型发布表单数据(而不是创建我自己的 DTO 类型)。
谢谢!
我们有一个带有Microsoft Identity表的现有SQL数据库,最初由ASP.NET Core应用程序生成.
我们还有一个ASP.NET 4应用程序,它也使用Microsoft Identity.
我们希望ASP.NET 4应用程序能够使用与原始.NET Core应用程序相同的数据库来验证登录.
但是,当我们尝试验证密码时,它们不匹配.
我只是猜测.NET 4应用程序生成的密码哈希值无法通过ASP.NET 4应用程序验证,但我不确定从何处开始.:)
.NET Core应用程序中没有自定义密码散列,我很难找到任何可能影响散列的配置?
非常感谢任何帮助或指针!
编辑:似乎这可能是由Identity V2/V3中的不同哈希算法引起的.但是不知道如何在ASP.NET 4应用程序中模仿V3散列算法.
我有一个针对多个框架的项目,在我的文件中使用<TargetFrameworks>(复数).csproj。
这工作正常,但我无法执行特定于框架的操作,.csproj因为该$(TargetFramework)属性始终为空。
如果我使用(单一)针对单个框架<TargetFramework>,一切都会按预期工作。
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net5.0;net6.0;net7.0</TargetFrameworks>
</PropertyGroup>
<Target Name="DoSomethingFrameworkSpecific" AfterTargets="Build">
<Message Text="$(TargetFramework)" /><!-- Empty string -->
</Target>
<ItemGroup>
<None Include="MyProject.targets">
<Pack>True</Pack>
<PackagePath>build\$(TargetFramework)</PackagePath><!-- File ends up in \build, not build\net5.0 etc -->
</None>
</ItemGroup>
</Project>
Run Code Online (Sandbox Code Playgroud)
我的印象是,MSBuild会为每个通道(即每个框架)传递当前框架版本,以便我们可以根据正在构建的版本执行特定于框架的路径或其他条件等操作?
官方文档表明这是可能的: https: //learn.microsoft.com/en-us/dotnet/standard/frameworks#how-to-specify-a-target-framework
SO 的相关问题似乎只处理预处理器指令,而不是在 MSBuild 脚本中获取当前框架版本。
我想用NEST附加多个bool过滤器,但我不能(实际上)在一个语句中执行它,因为我想根据不同的条件构建一组Bool过滤器.
像这样的伪代码:
// Append a filter
searchDescriptor.Filter(f => f.Bool(b => b.Must(m => m.Term(i => i.SomeProperty, "SomeValue"))));
if (UserId.HasValue)
{
// Optionally append another filter (AND condition with the first filter)
searchDescriptor.Filter(f => f.Bool(b => b.Must(m => m.Term(i => i.AnotherProperty, "MyOtherValue"))));
}
var result = Client.Search(searchDescriptor);
Run Code Online (Sandbox Code Playgroud)
现在看来,当附加第二个可选过滤器时,它基本上取代了第一个过滤器.
我确定我在语法上遗漏了一些东西,但我无法弄明白,过滤器DSL上的NEST文档有点薄.:)
我有一个ASP.NET核心应用程序,在本地运行良好.
但是,当我将站点发布(Web部署)到Azure时,我得到403 : You do not have permission to view this directory or page.
我有一个默认控制器和Startup.cs中定义的路由:
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller}/{action}/{id?}",
defaults: new { controller = "Home", action = "Index" });
});
Run Code Online (Sandbox Code Playgroud)
Web部署到Azure后的文件夹结构如下所示:
|_ home
|_ site
|_ wwwroot (contains DLL's and files specified through 'publishOptions' in project.json)
|_ wwwroot (the contents of the 'wwwroot' folder I have in Visual Studio)
|_ Views (contains MVC views)
|_ refs (contains referenced …Run Code Online (Sandbox Code Playgroud) 我创建了一个 ASP.NET Core 2.1应用程序,我正在尝试将其部署到Google Cloud Platform。dotnet build在本地使用它构建得很好。
不过,我无法通过 Google Cloud Shell 构建它。运行dotnet --version确认 Google Cloud Shell 已安装.NET Core 2.0。
运行会gcloud app deploy启动应用程序的部署,但我从日志中收到一个神秘的错误:
第 0 步:状态:为 gcr.io/gcp-runtimes/aspnetcorebuild@sha256 下载了较新的映像:ad1b788a9b4cca75bb61eb523ef358ca059c4bd208fba15a10ccc6acab83f49a
步骤 #0:没有找到应用程序的 .deps.json 文件 完成步骤 #0
错误:构建步骤 0“gcr.io/gcp-runtimes/aspnetcorebuild@sha256:ad1b788a9b4cca75bb61eb523ef358ca059c4bd208fba15a10ccc6acab83f49a”失败:退出状态 1
我的印象是 GCP默认支持 .NET Core 2.1容器,所以我没有包含Dockerfile。
我正在尝试部署到灵活的环境,这是我的app.yaml文件:
runtime: aspnetcore
env: flex
Run Code Online (Sandbox Code Playgroud)
我需要创建自定义 Docker 容器吗?或者是否有其他方法可以在 Google Cloud Shell 中获得对 .NET Core 2.1 的支持?
编辑:现在我已经安装了谷歌云工具,gcloud app deploy在运行 …
google-cloud-platform .net-core asp.net-core google-cloud-shell
我正在尝试使用服务帐户通过 Google 我的商家 API 检索位置/评论。
到目前为止我有:
当使用 Google 的示例 .NET 客户端(可从https://developers.google.com/my-business/sampleshttps://mybusiness.googleapis.com/v4/accounts/[ACCOUNT NAME]/invitations下载)以编程方式列出邀请时,我可以看到邀请
但是,当我尝试通过请求接受邀请时,请求https://mybusiness.googleapis.com/v4/accounts/[ACCOUNT NAME]/invitations/[INVITATION NAME]:accept失败并出现 500 服务器错误。
创建MyBusinessService实例时,我首先创建一个服务帐户凭据,例如:
ServiceAccountCredential credential;
using (Stream stream = new FileStream("credentials.json", FileMode.Open, FileAccess.Read, FileShare.Read))
{
credential = (ServiceAccountCredential)GoogleCredential
.FromStream(stream)
.CreateScoped(new [] { "https://www.googleapis.com/auth/plus.business.manage" })
.UnderlyingCredential;
}
Run Code Online (Sandbox Code Playgroud)
接下来我创建一个初始化程序,例如:
var initializer = new BaseClientService.Initializer()
{
HttpClientInitializer = credential,
ApplicationName = "My GMB API Client",
GZipEnabled = …Run Code Online (Sandbox Code Playgroud) Optimizely CMS(艺术家以前称为EPiServer)最近发布了.Net Core版本。我可以使用 Kestrel 运行我的网站。但是,我想为我的网站设置一个特定的 url,并且我想为此 url 使用现有的 SSL 证书。
该证书安装在我的计算机上的 WebHosting 商店中。
这是我的 Kestrel 配置:
启动设置.json
"MySampleProject": {
"commandName": "Project",
"launchBrowser": true,
"externalUrlConfiguration": true,
"applicationUrl": "https://sampleproject.local.hostname.dev",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
Run Code Online (Sandbox Code Playgroud)
应用程序设置.json
"Kestrel": {
"Endpoints": {
"HttpsInlineCertStore": {
"Url": "https://sampleproject.local.hostname.dev",
"Certificate": {
"Subject": "local.hostname.dev",
"Store": "WebHosting",
"Location": "LocalMachine",
"AllowInvalid": "true"
}
}
}
Run Code Online (Sandbox Code Playgroud)
在程序.cs中
public static IHostBuilder CreateHostBuilder(string[] args, bool isDevelopment)
{
return Host.CreateDefaultBuilder(args)
.ConfigureCmsDefaults()
.UseSerilog()
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.ConfigureKestrel(serverOptions => serverOptions.AddServerHeader = false);
webBuilder.UseStartup<Startup>();
})
.ConfigureLogging(logging => …Run Code Online (Sandbox Code Playgroud) 假设我有这样的代码:
if (someEnumerable.Count() < 2) {
// Do something
}
Run Code Online (Sandbox Code Playgroud)
这是否会导致someEnumerable完全迭代,或者如果Count()到达可枚举中的第二项,评估是否会完成?
asp.net-core ×3
.net-core ×2
asp.net ×2
azure ×2
c# ×2
asp.net-mvc ×1
cil ×1
clr ×1
database ×1
deployment ×1
google-api ×1
kestrel ×1
kudu ×1
msbuild ×1
nest ×1
webdeploy ×1