小编Dav*_*New的帖子

Azure表存储批处理跨多个分区插入?

以下方法可用于将实体集合批量插入为单个事务:

CloudTable.ExecuteBatch(TableBatchOperation batch)
Run Code Online (Sandbox Code Playgroud)

如果在插入期间任何实体失败,则不会从集合中插入任何内容.这仅在插入一个分区时可用.

是否可以跨多个分区执行此类操作?

c# azure azure-storage azure-table-storage

11
推荐指数
1
解决办法
3890
查看次数

隐式运算符应该处理null吗?

我们有一个具有隐式字符串运算符的类型.它看起来像这样:

public class Foo
{
    readonly string _value;

    Foo(string value)
    {
        _value = value;
    }

    public static implicit operator string(Foo foo)
    {
        return foo._value;
    }

    public static implicit operator Foo(string fooAsText)
    {
        return new Foo(fooAsText);
    }

}
Run Code Online (Sandbox Code Playgroud)

我们刚刚有一个实例传递给隐式运算符null的场景.显然,我们最终得到了一个NullReferenceException.

我认为这是很公平的,毕竟,什么是一个类型,它是空的字符串表示 - 很难说 - 这样的例外似乎是有效的,这是我们不应该拦截/禁止/手柄/忽略.我的理由是'有人给我一个空的,为什么我应该返回null.我不会在其他方法中这样做.我想,'我知道,我会在转换之前检查null',类似于:

string s = foo == null ? null : foo;

但这没有用,因为它现在在比较之前转换为字符串为null.当然,这种比较可行:

Foo f = null;
string s;
if (f != null)
{
    s = f;
}
Run Code Online (Sandbox Code Playgroud)

......但那只是丑陋的.

我阅读了Essential …

c# exception-handling implicit-conversion

10
推荐指数
2
解决办法
2365
查看次数

Azure Web App中的ASP.NET 5环境名称

在发布到Azure Web Apps时,最好为ASP.NET 5 Web应用程序的每个部署设置环境名称?

我知道ASPNET_DEV需要设置环境变量.发布时这可能吗?

这是我们的powershell发布脚本:

param($websiteName, $packOutput)

$website = Get-AzureWebsite -Name $websiteName

# get the scm url to use with MSDeploy.  By default this will be the second in the array
$msdeployurl = $website.EnabledHostNames[1]

$publishProperties = @{'WebPublishMethod'='MSDeploy';
                        'MSDeployServiceUrl'=$msdeployurl;
                        'DeployIisAppPath'=$website.Name;
                        'Username'=$website.PublishingUsername;
                        'Password'=$website.PublishingPassword}

Write-Output "Restarting web app..."
Restart-AzureWebsite -Name $websiteName

Write-Output "Publishing web app..."
$publishScript = "${env:ProgramFiles(x86)}\Microsoft Visual Studio 14.0\Common7\IDE\Extensions\Microsoft\Web Tools\Publish\Scripts\default-publish.ps1"

. $publishScript -publishProperties $publishProperties  -packOutput $packOutput
Run Code Online (Sandbox Code Playgroud)

或者我们是否在Azure门户中设置了环境变量?部署之间会持续存在吗?

我正在使用ASP.NET 5 beta6库与dnx451目标框架,如果这很重要.

azure azure-web-sites asp.net-core-mvc dnx asp.net-core

10
推荐指数
1
解决办法
1835
查看次数

无法在Azure中访问我的X509Certificate2的PrivateKey

我将X509Certificate存储在数据库(in byte[])中,以便我的应用程序可以检索证书并使用它来签署我的JWT.

我的x509Certificate是从我在我的机器上生成的.pfx文件传递出来的,但现在它作为字节串存在于数据库中.

我运行它时,我的应用程序在本地工作得很好.应用程序可以正确创建该X509Certificate2的实例并将其用于我的要求,但是当我尝试在我的azurewebsites Web应用程序中使用它时会出现问题.

基本上我无法访问证书的PrivateKey实例变量,我得到一个例外

System.Security.Cryptography.CryptographicException: Keyset does not exist
Run Code Online (Sandbox Code Playgroud)

我正在用这个重新实例化证书

var cert = new X509Certificate2(myCertInBytes, myCertPass,
            X509KeyStorageFlags.PersistKeySet |
            X509KeyStorageFlags.MachineKeySet |
            X509KeyStorageFlags.Exportable);
Run Code Online (Sandbox Code Playgroud)

我正在使用ASPNET 5 rc1-update1.我也试过在另一台机器上运行它,它工作正常,只有在我发布到Azure时才会出现这个问题.并且还要添加其他内容,当我运行使用DNX版本beta7运行的相同项目时,此应用程序正在运行

任何帮助赞赏.

azure x509certificate azure-web-sites asp.net-core

10
推荐指数
1
解决办法
1897
查看次数

使用UseJwtBearerAuthentication中间件的自定义401和403响应模型

当401和403出现时,我想用JSON响应模型做出响应.例如:

HTTP 401
{
  "message": "Authentication failed. The request must include a valid and non-expired bearer token in the Authorization header."
}
Run Code Online (Sandbox Code Playgroud)

我正在使用中间件(如本答案中所建议的)拦截404并且它工作得很好,但401或403并非如此.这是中间件:

app.Use(async (context, next) =>
{
    await next();
    if (context.Response.StatusCode == 401)
    {
        context.Response.ContentType = "application/json";
        await context.Response.WriteAsync(JsonConvert.SerializeObject(UnauthorizedModel.Create(), SerializerSettings), Encoding.UTF8);
    }
});
Run Code Online (Sandbox Code Playgroud)

当置于下方app.UseJwtBearerAuthentication(..)Startup.Configure(..),它似乎被完全忽略并返回正常的401.

当置于ABOVE app.UseJwtBearerAuthentication(..)中时Startup.Configure(..),将抛出以下异常:

连接标识"0HKT7SUBPLHEM":应用程序抛出了未处理的异常.System.InvalidOperationException:标头是只读的,响应已经开始.在MicrosoftPro.AspNetCore.Server.Kestrel.Internal.Http.FrameHeaders.Microsoft.AspNetCore.Http.IHeaderDictionary.set_Item(String key,StringValues value),位于MyProject的Microsoft.AspNetCore.Http.Internal.DefaultHttpResponse.set_ContentType(String value). Startup.cs中的Api.Startup.<b__12_0> d.MoveNext()

asp.net-core-mvc asp.net-core asp.net-core-1.0

10
推荐指数
2
解决办法
5906
查看次数

来自Azure Web App的一个实例的HTTP 502

我们突然开始The specified CGI application encountered an error and the server terminated the process从我们的Web应用程序的一个实例中遇到HTTP 502错误().我能够使用Kudu的"支持"选项卡确定这一点,您可以深入查看每个实例的指标.

重新启动w3wp后,所有内容都正常继续成功.资源使用(CPU/RAM)没有问题,奇怪的是502s立即返回.因此,请求不会为客户端超时.

调查为什么会发生这种情况的可能步骤是什么?

我们的应用程序日志没有任何内容,我们的Web服务器日志只有这些502的记录,但没有进一步的细节.

azure azure-diagnostics azure-web-sites azure-app-service-envrmnt azure-app-service-plans

10
推荐指数
1
解决办法
1054
查看次数

Azure DevOp管道认证到AKS配置Azure AD RBAC?

我们已将Azure Kubernetes Clusters配置为使用Azure Active Directory RBAC.这意味着当使用kubectl时,我们需要首先作为AD用户进行身份验证(通常通过Web浏览器手动完成设备代码身份验证).我们几乎完全按照MSDN文章" 将Azure Active Directory与Azure Kubernetes服务集成"进行了配置.

问题是,现在,Azure DevOp管道中的Kubernetes构建/发布任务也需要此身份验证,例如,当我们运行kubectl apply时:

2019-01-02T08:48:21.2070286Z ##[section]Starting: kubectl apply
2019-01-02T08:48:21.2074936Z ==============================================================================
2019-01-02T08:48:21.2075160Z Task         : Deploy to Kubernetes
2019-01-02T08:48:21.2075398Z Description  : Deploy, configure, update your Kubernetes cluster in Azure Container Service by running kubectl commands.
2019-01-02T08:48:21.2075625Z Version      : 1.1.17
2019-01-02T08:48:21.2075792Z Author       : Microsoft Corporation
2019-01-02T08:48:21.2076009Z Help         : [More Information](https://go.microsoft.com/fwlink/?linkid=851275)
2019-01-02T08:48:21.2076245Z ==============================================================================
2019-01-02T08:48:25.7971481Z Found tool in cache: kubectl 1.7.0 x64
2019-01-02T08:48:25.7980222Z Prepending PATH environment variable with directory: C:\agents\HephaestusForge\_work\_tool\kubectl\1.7.0\x64
2019-01-02T08:48:25.8666111Z [command]C:\agents\HephaestusForge\_work\_tool\kubectl\1.7.0\x64\kubectl.exe apply -f C:\agents\HephaestusForge\_work\r8\a\_MyProject\kubernetes\deploy.yaml …
Run Code Online (Sandbox Code Playgroud)

azure azure-active-directory azure-devops azure-pipelines azure-kubernetes

10
推荐指数
2
解决办法
849
查看次数

Web角色和云服务的多站点策略

我们有3个面向公众的Web应用程序,我们正在迁移到Azure.所有站点都使用端口80.

OPTIONS

据我所知,使用Web角色时有三种不同的选择:

1.在单个云服务中以一个Web角色托管的所有3个站点:

  • 可以通过hostHeader配置HTTP访问 ServiceDefinition.csdef
  • 这是最便宜的
  • 要求所有项目需要同时发布
  • 这些网站不能单独扩展,只能作为一个整体
  • 1 Visual Studio中的Cloud Service项目

2.在单个云服务中托管在SEPARATE Web角色上的每个站点:

  • 可以通过hostHeader配置HTTP访问 ServiceDefinition.csdef
  • 每个站点都有自己的实例
  • 要求所有项目需要同时发布
  • 这些网站可以单独扩展
  • 1 Visual Studio中的Cloud Service项目

3.在SEPARATE云服务中的Web角色上托管的每个站点:

  • 每个站点都有自己的cloudapp.net DNS和IP
  • 每个站点都有自己的实例
  • 网站可以单独发布
  • 这些网站可以单独扩展
  • Visual Studio中的多个Cloud Service项目

我还缺少其他重要的东西吗?

可能的解决方案

选项1和2的组合.

在一个云服务中托管所有内容:将它们全部发布在一起很好,因为它们都引用了一个需要在所有项目中一致更新的公共库项目.

在一个Web角色中托管两个站点:它们可以很好地扩展.

在其自己的Web角色中托管第三个站点由于大量的峰值需求,它需要自己的扩展.

ServiceDefinition.csdef:

<ServiceDefinition name="WebTestCloudService.Test" xmlns="..." schemaVersion="2012-10.1.8">
  <WebRole name="AzureWebTest1" vmsize="Small">
    <Sites>
      <Site name="AzureWebTest1">
        <Bindings>
          <Binding name="Endpoint1" endpointName="Endpoint1" hostHeader="test1.mydomain.com" />
        </Bindings>
      </Site>
    </Sites>
    <Endpoints>
      <InputEndpoint name="Endpoint1" protocol="http" port="80" />
    </Endpoints>
  </WebRole>
  <WebRole name="AzureWebTest2" vmsize="Small">
    <Sites> …
Run Code Online (Sandbox Code Playgroud)

.net cloud azure azure-web-roles azure-sql-database

9
推荐指数
1
解决办法
2226
查看次数

更改服务层或性能级别以及数据库停机时间

我已经确定我们可能需要很快扩展到下一个服务层(标准到高级).

对于其他感兴趣的人,本文为分析SQL数据库提供了很好的指导.

我的问题: 在扩展到不同的服务层或性能级别时是否有任何停机时间?

azure azure-sql-database

9
推荐指数
3
解决办法
3683
查看次数

MVC 6 Web Api:解析201(创建)上的位置标题

在Web Api 2.2中,我们可以通过从控制器返回来返回位置标头URL,如下所示:

return Created(new Uri(Url.Link("GetClient", new { id = clientId })), clientReponseModel);
Run Code Online (Sandbox Code Playgroud)

Url.Link(..)将根据控制器名称相应地解析资源URL GetClient:

位置标题

在ASP.NET 5 MVC 6的Web Api中,Url框架中不存在但CreatedResult构造函数确实具有location参数:

return new CreatedResult("http://www.myapi.com/api/clients/" + clientId, journeyModel);
Run Code Online (Sandbox Code Playgroud)

如何在不必手动提供此URL的情况下解析此URL,就像我们在Web API 2.2中所做的那样?

asp.net-core-mvc dnx asp.net-core

9
推荐指数
2
解决办法
9489
查看次数