小编Pou*_*sen的帖子

使用基本身份验证向Katana Hosted WebAPI添加cookie

我已经为Katana实现了一个基本认证中间件(下面的代码).

(我的客户端托管在跨域,然后是实际的API).

如果满足以下条件,浏览器可以跳过预检请求:

请求方法是GET,HEAD或POST,并且应用程序不会设置除Accept,Accept-Language,Content-Language,Content-Type或Last-Event-ID以及Content-Type标头之外的任何请求标头( if set)是以下之一:application/x-www-form-urlencoded multipart/form-data text/plain

在javascript中,我在服务器接受请求的所有请求上设置了认证头(使用jquery,beforeSend).这意味着上面将发送所有请求的选项请求.我不想那样.

function make_base_auth(user, password) {
    var tok = user + ':' + password;
    var hash = Base64.encode(tok);
    return "Basic " + hash;
}
Run Code Online (Sandbox Code Playgroud)

我该怎么做才能解决这个问题?我的想法是在用户身份验证后将用户信息存储在cookie中.

我还在katana项目中看到了Microsoft.Owin.Security.Cookies - 这可能是我想要的而不是我自己的基本身份验证吗?

BasicAuthenticationMiddleware.cs

using Microsoft.Owin;
using Microsoft.Owin.Logging;
using Microsoft.Owin.Security.Infrastructure;
using Owin;

namespace Composite.WindowsAzure.Management.Owin
{
    public class BasicAuthenticationMiddleware : AuthenticationMiddleware<BasicAuthenticationOptions>
    {
        private readonly ILogger _logger;

        public BasicAuthenticationMiddleware(
           OwinMiddleware next,
           IAppBuilder app,
           BasicAuthenticationOptions options)
            : base(next, options)
        {
            _logger = app.CreateLogger<BasicAuthenticationMiddleware>();
        }

        protected override AuthenticationHandler<BasicAuthenticationOptions> CreateHandler()
        {
            return new …
Run Code Online (Sandbox Code Playgroud)

c# asp.net-web-api owin katana

5
推荐指数
1
解决办法
3141
查看次数

如何使用WebAPI从Rest API上下扩展Azure云服务

我正在创建一个演示,我需要能够从WebAPI扩展我的云服务部署.

我查看了其余的API文档,但似乎找不到我需要的内容.

是否可以使用Service Management API来上下扩展云服务?

替代方案我将在队列上启用自动缩放,然后将消息发布到队列以使其扩展:)

azure

5
推荐指数
1
解决办法
1127
查看次数

是否可以将异步方法作为回调到c#中的事件处理程序?

我的设计由下面的例子说明.有一段时间真正的循环做某事并通过事件通知它已经对所有订阅者做了一些事情.我的应用程序在完成通知所有订阅者之前不应该继续执行它,只要有人不在回调上放置异步空格就可以.

如果有人在回调上放置异步void以等待某个任务,那么我的循环可以在回调完成之前继续.我可以采取哪些其他设计来避免这种情况.

它的第3方插件注册了自己并订阅了这个事件,所以我无法控制它们是否存在异步空白.可以理解我不能为EventHandler做任务回调,所以我有什么替代品.net 4.5.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace ConsoleApplication4
{
    public class Test
    {

        public event EventHandler Event;

        public void DoneSomething()
        {
            if (Event != null)
                Event(this,EventArgs.Empty);
        }
    }
    class Program
    {
        static void Main(string[] args)
        {
            var test = new Test();

            test.Event += test_Event;
            test.Event +=test_Event2;

            while(true)
            {
                test.DoneSomething();
                Thread.Sleep(1000);

            }
        }

        private static void test_Event2(object sender, EventArgs e)
        {
            Console.WriteLine("delegate 2");
        }

        static async void test_Event(object sender, EventArgs e) …
Run Code Online (Sandbox Code Playgroud)

c# async-await

5
推荐指数
1
解决办法
1017
查看次数

使用 TFS 在线服务构建时,有什么方法可以对 Clickonce 应用程序进行签名?

我已启用登录一次单击应用程序。

但是构建服务器(TFS 在线服务)没有证书。有什么方法可以将证书包含在存储库中并使构建服务器对其进行签名,还是必须禁用签名并在之后手动执行?

我没有从商店中挑选证书,而是检入了一个文件并从文件中挑选。

构建服务器然后给我:

C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Microsoft.Common.targets (2482):无法导入以下密钥文件:. 密钥文件可能受密码保护。要更正此问题,请尝试再次导入证书或手动将证书导入当前用户的个人证书存储区。

(是否打算让我在没有密码的情况下签入一个,而其他人是这样做的吗?在没有密码的情况下拥有私钥并不危险。)

tfs azure-devops

5
推荐指数
2
解决办法
1127
查看次数

从ASP.NET Core日志记录中删除日志中的敏感信息

我正在为我的应用程序使用ASP.NET Core日志抽象.

我有一个敏感字符串列表,我希望确保在发送到任何接收器时在日志中屏蔽"*****".(我正在使用serilog - 但也许它甚至可以在serilog之前插入).

我如何将其插入ASP.NET Core日志系统,以便在发送到任何接收器/写入器之前用"*******"替换所有这些敏感字符串.

.net .net-core .net-core-logging

5
推荐指数
1
解决办法
1231
查看次数

响应标头不适用于带有“重定向:手动”的提取请求

我在做

        console.log("navigating");
        var rsp = await fetch(params.url, {
            credentials: "include", redirect: "manual", mode: "cors"
        });
        console.log(rsp);
        rsp.headers.forEach(console.log);

        console.log(rsp.headers.get('Location'));
        console.log(rsp.headers.get('location'));
Run Code Online (Sandbox Code Playgroud)

以及chrome开发工具的响应标头:

Access-Control-Allow-Credentials: true
Access-Control-Allow-Origin: http://localhost:4400
Access-Control-Expose-Headers: Location
Cache-Control: no-cache
Connection: keep-alive
Content-Length: 0
Date: Fri, 05 Oct 2018 12:48:21 GMT
Expires: Thu, 01 Jan 1970 00:00:00 GMT
Location: http://localhost/test
Run Code Online (Sandbox Code Playgroud)

Response 
body: (...)
bodyUsed: falseheaders: 
Headers {}
ok: false
redirected: false
status: 0
statusText: ""
type: "opaqueredirect"
url: "..."

index.ts:161 null
index.ts:162 null
Run Code Online (Sandbox Code Playgroud)

是否无法在重定向响应中获取响应头?

fetch-api

5
推荐指数
1
解决办法
894
查看次数

CryptographicException:启用WIF的MVC 4中的数据无效

我创建了一个MVC 4项目并为Azure ACS设置它.它与System.Identity一起使用.我将其更改为使用Microsoft.Identity启用WIF,我的配置文件现在看起来像这样:

<?xml version="1.0" encoding="utf-8"?>
<!--
  For more information on how to configure your ASP.NET application, please visit
  http://go.microsoft.com/fwlink/?LinkId=169433
  -->
<configuration>
  <configSections>
    <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=4.4.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
    <section name="microsoft.identityModel"
             type="Microsoft.IdentityModel.Configuration.MicrosoftIdentityModelSection, Microsoft.IdentityModel, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
  </configSections>
  <connectionStrings>

    <add name="DefaultConnection"  />
  </connectionStrings>
  <appSettings>
    <add key="webpages:Version" value="2.0.0.0" />
    <add key="webpages:Enabled" value="false" />
    <add key="PreserveLoginUrl" value="true" />
    <add key="ClientValidationEnabled" value="true" />
    <add key="UnobtrusiveJavaScriptEnabled" value="true" />
    <add key="ida:FederationMetadataLocation" …
Run Code Online (Sandbox Code Playgroud)

c# security .net-4.0 windows-identity wif

4
推荐指数
1
解决办法
5855
查看次数

我如何从一个方法返回一个Eigen :: Matrix,这样它在返回时不会复制数据

我有:

Eigen::MatrixXf load_from_gpu()
{
    Eigen::MatrixXf mat(m_rows,m_cols);
    clEnqueueReadBuffer(m_manager->m_gpu_queue_loader, m_buffer, CL_TRUE, 0, sizeof(float)*numel(), mat.data(), 0, NULL, NULL); 
    return mat; 
}
Run Code Online (Sandbox Code Playgroud)

我相信当我调用此方法时,数据会存储到一个垫子然后复制到mat2: Eigen::MatrixXf mat2 = load_from_gpu();

是否可以将数据写入矩阵,该矩阵是函数调用的rhs load_from_gpu()

eigen

4
推荐指数
1
解决办法
3600
查看次数

Katana Webserver没有找到clientSecret

我下载了katana项目,想在沙箱项目中尝试客户端/服务器.

我为OAuthValidateClientAuthenticationContext遇到了一个问题:

public bool TryGetFormCredentials(out string clientId, out string clientSecret)
{
    clientId = Parameters.Get(Constants.Parameters.ClientId);
    if (!String.IsNullOrEmpty(clientId))
    {
        clientSecret = Parameters.Get(Constants.Parameters.ClientSecret);
        ClientId = clientId;
        return true;
    }
    clientId = null;
    clientSecret = null;
    return false;
}
Run Code Online (Sandbox Code Playgroud)

clientSecret为null,因此以下内容未验证客户端.

    private Task ValidateClientAuthentication(OAuthValidateClientAuthenticationContext context)
    {
        string clientId;
        string clientSecret;
        if (context.TryGetBasicCredentials(out clientId, out clientSecret) ||
            context.TryGetFormCredentials(out clientId, out clientSecret))
        {
            if (clientId == "123456" && clientSecret == "abcdef")
            {
                context.Validated();
            }
            else if (context.ClientId == "7890ab" && clientSecret == "7890ab")
            {
                context.Validated();
            }
        } …
Run Code Online (Sandbox Code Playgroud)

owin katana

4
推荐指数
1
解决办法
1722
查看次数

如何通过使用 Microsoft 增强型 RSA 和 AES 加密提供程序的 CertificateRequest 创建自签名证书

我正在使用 dotnet core 构建一个证书,如下所示:

    private X509Certificate2 buildSelfSignedServerCertificate(string CertificateName,string password,string dns)
    {
        SubjectAlternativeNameBuilder sanBuilder = new SubjectAlternativeNameBuilder();
        sanBuilder.AddIpAddress(IPAddress.Loopback);
        sanBuilder.AddIpAddress(IPAddress.IPv6Loopback);
        if (!string.IsNullOrEmpty(dns))
        {
            sanBuilder.AddDnsName(dns);
        }
      // 
      //  sanBuilder.AddDnsName(Environment.MachineName);

        X500DistinguishedName distinguishedName = new X500DistinguishedName($"CN={CertificateName}");

        using (RSA rsa = RSA.Create(2048*2))
        {
            var request = new CertificateRequest(distinguishedName, rsa, HashAlgorithmName.SHA256, RSASignaturePadding.Pkcs1);

            //request.CertificateExtensions.Add(
            //    new X509KeyUsageExtension(X509KeyUsageFlags.DataEncipherment | X509KeyUsageFlags.KeyEncipherment | X509KeyUsageFlags.DigitalSignature, false));


            //request.CertificateExtensions.Add(
            //   new X509EnhancedKeyUsageExtension(
            //       new OidCollection { new Oid("1.3.6.1.5.5.7.3.1"), new Oid("1.3.6.1.5.5.7.3.2") }, false));

            request.CertificateExtensions.Add(sanBuilder.Build());

            var certificate = request.CreateSelfSigned(new DateTimeOffset(DateTime.UtcNow.AddDays(-1)), new DateTimeOffset(DateTime.UtcNow.AddDays(3650)));
             bool isWindows = System.Runtime.InteropServices.RuntimeInformation …
Run Code Online (Sandbox Code Playgroud)

c# certificate .net-core

4
推荐指数
1
解决办法
4674
查看次数