小编VSD*_*kar的帖子

为HTTPS配置ASP.NET Core 2.0 Kestrel

TL; DR今天使用ASP.NET Core 2.0设置HTTPS的正确方法是什么?

我想将我的项目配置为使用https和他们在BUILD 2017中展示的证书.我尝试了几个设置,但没有任何效果.经过一番研究,我更加困惑.看来,有很多方法可以配置URL和端口.我已经看到了appsettings.json,hosting.json通过代码,在launchsettings.json我们还可以设置URL和端口.

有"标准"的方法吗?

这是我的 appsettings.development.json

{
  "Kestrel": {
    "Endpoints": {
      "Localhost": {
        "Address": "127.0.0.1",
        "Port": "40000"
      },
      "LocalhostWithHttps": {
        "Address": "127.0.0.1",
        "Port": "40001",
        "Certificate": {
          "HTTPS": {
            "Source": "Store",
            "StoreLocation": "LocalMachine",
            "StoreName": "My",
            "Subject": "CN=localhost",
            "AllowInvalid": true
          }
        }
      }
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

但是launchsettings.json当我从命令行dotnet run开始或从Visual Studio开始使用调试器时,它始终需要url和port .

这是我Program.csStartup.cs

public class Program
{
    public static void Main(string[] args)
    {
        BuildWebHost(args).Run();
    }

    public …
Run Code Online (Sandbox Code Playgroud)

c# kestrel-http-server asp.net-core asp.net-core-2.0

19
推荐指数
1
解决办法
2万
查看次数

使用ASP.Net Core在VSCode中调试Typescript

这时我正在尝试创建一个基于ASP.Net Core(C#)的React Web应用程序.我在TypeScript中编写了代码.我将我的代码与Webpack捆绑在一起.源地图已启用.

现在我想在Visual Studio Code中调试我的(Typescript)代码.Chrome中的调试效果很好.所以源地图都正常工作.

这可能吗?我在使用Node.js服务器时发现了很多东西/教程,但在使用ASP.Net Core时却没有.

谢谢你指点我正确的方向.或者甚至更好,编写一个小教程,我将如何设置我的VSCode(launch.json等)

debugging typescript webpack visual-studio-code asp.net-core

15
推荐指数
2
解决办法
2815
查看次数

如何在 Typescript 中使用 ES6 代理?

我想尝试一些有关代理的事情,但我很难让最简单的形式运行。

我有以下代码

const myObj = {
  x: 'Hello',
};

const p = new Proxy(myObj, {
  get: (target, key) => {
    return key in target ? target[key] + ' World!' : 'nope';
  },
});

console.log(p.x);
Run Code Online (Sandbox Code Playgroud)

我收到以下错误,但我不知道为什么以及如何解决它:

index.ts:7:28 - error TS7053: Element implicitly has an 'any' type because expression of type 'string | number | symbol' can't be used to index type '{ x: string; }'.
  No index signature with a parameter of type 'string' was found on type '{ x: string; …
Run Code Online (Sandbox Code Playgroud)

typescript

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

TypeScript类型检查JSX子项

我的TypeScript版本是 2.3.2

根据这个类型检查JSX的孩子

以下代码应该有效:

import * as React from 'react';
import * as ReactDOM from 'react-dom';

interface TestProps {
    children: string | JSX.Element;
}

const Foo = (props: TestProps) => <div>{props.children}</div>;

// Error on Foo
ReactDOM.render(
    <Foo>
        <div>Test</div>
    </Foo>,
    document.getElementById('content'),
);
Run Code Online (Sandbox Code Playgroud)

但是我得到以下编译错误:

TestTsxChildren> tsc --version
Version 2.3.2
TestTsxChildren> tsc
main.tsx(11,5): error TS2322: Type '{}' is not assignable to type 'IntrinsicAttributes & TestProps'.
  Type '{}' is not assignable to type 'TestProps'.
    Property 'children' is missing in type '{}'.
Run Code Online (Sandbox Code Playgroud)

我做错了什么?或者我不明白这个问题试图修复什么?

typescript react-jsx

7
推荐指数
1
解决办法
1763
查看次数

SqlDataReader 和 SQL Server 2016 FOR JSON 将 json 拆分为 2k 字节的块

最近,我尝试for json auto了 Azure SQL 数据库的新功能。

例如,当我使用此查询选择大量记录时:

Select
    Wiki.WikiId
    , Wiki.WikiText
    , Wiki.Title
    , Wiki.CreatedOn
    , Tags.TagId
    , Tags.TagText
    , Tags.CreatedOn
From
    Wiki
Left Join
    (WikiTag
Inner Join 
    Tag as Tags on WikiTag.TagId = Tags.TagId) on Wiki.WikiId = WikiTag.WikiId
For Json Auto
Run Code Online (Sandbox Code Playgroud)

然后用 C# 做一个选择SqlDataReader

var connectionString = ""; // connection string
var sql = "";  // query from above
var chunks = new List<string>();

using (var connection = new SqlConnection(connectionString)) 
using (var command = connection.CreateCommand()) …
Run Code Online (Sandbox Code Playgroud)

c# t-sql sql-server sql-server-2016 azure-sql-database

6
推荐指数
1
解决办法
1179
查看次数

Newtonsoft JsonConvert.DeserializeObject 如何忽略空对象

我有以下类定义:

public class Tag
{
    public Guid? TagId { get; set; }
    public string TagText { get; set; }
    public DateTime CreatedOn { get; set; }
}

public class Wiki
{
    public Guid? WikiId { get; set; }
    public string WikiText { get; set; }
    public string Title { get; set; }
    public DateTime CreatedOn { get; set; }
    public IEnumerable<Tag> Tags { get; set; }
}
Run Code Online (Sandbox Code Playgroud)

从数据库中我得到以下 json 对象:

{
    "WikiId": "83981284-0AD3-4420-90AB-15E3BF6BD7B7",
    "WikiText": "Text",
    "Title": "Title",
    "CreatedOn": "2017-08-07T09:16:06.0800000",
    "Tags": …
Run Code Online (Sandbox Code Playgroud)

c# json.net

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

无法调用扩展方法时的隐式转换

为什么在调用扩展方法时不可能使用隐式转换?

以下是示例代码:

using System;

namespace IntDecimal
{
    class Program
    {
        static void Main(string[] args)
        {
            decimal d = 1000m;
            int i = 1000;

            d = i; // implicid conversion works just fine

            Console.WriteLine(d.ToNumberString()); // Works as expected
            Console.WriteLine(i.ToNumberString()); // Error
            Console.WriteLine(ToNumberString2(i)); // Implicid conversion here works just fine
        }

        static string ToNumberString2(decimal d)
        {
            return d.ToString("N0");
        }
    }

    public static class Ext
    {
        public static string ToNumberString(this decimal d)
        {
            return d.ToString("N0");
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

我得到的错误:'int'不包含'ToNumberString'的定义,最好的扩展方法重载'Ext.ToNumberString(decimal)'需要'decimal'类型的接收器

我们可以看到.存在从int到decimal的隐式转换,当我们不将它用作扩展方法时,它可以正常工作.

我知道我可以做些什么来使事情有效, 但是在使用扩展方法时,没有隐式演员可能的技术原因是什么?

c# roslyn

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

使用 Azure AD B2C 时如何控制/设置单个用户的权限

我有 1 个 SPA 应用程序,它使用另一个 WebApi。(ASP.NET Core)两者都在 Azure 中运行,我能够使用 OAuth 2.0 隐式流程对 Azure AD B2C 进行用户身份验证

现在我问自己如何控制单个用户的权限。(删除、读取等)我必须处理索赔吗?我是否必须利用服务器端的图形 API 来检查用户是否具有特定权限?我可以使用范围吗?在哪里可以设置 User <--> Scope 关系?

我发现了几个关于 SO 的问题,但我不知道应该如何以正确的方式完成它?我目前的理解是,我向身份验证提供商询问某些范围,然后我将获得具有此范围的令牌,然后可以通过 API 进行检查。但是我如何管理哪些用户可以请求哪些范围呢?

我真的很难理解 OAuth2 和权限。希望有人能在这里帮助我。

azure oauth-2.0 azure-active-directory azure-ad-b2c

2
推荐指数
1
解决办法
1179
查看次数

从 package.json 中脚本部分的配置文件中读取

是否可以从"scripts"package.json 部分中的配置文件中读取?

问题背景:我们是几个开发人员,他们都在同一台终端服务器上工作。我们的 package.json 中有以下部分

...
"scripts": {
    "serve": "vue-cli-service serve --port 8080"
}
...
Run Code Online (Sandbox Code Playgroud)

由于我们位于同一服务器上,因此我们需要一种方法来指定不同的端口。一种可能性是使用命令行参数。但我希望有一种“更简单”的方式,我可以将端口存储在我添加的配置文件中.gitignore,这样每个开发人员都可以拥有自己的文件,我们只需键入而npm run serve无需考虑输入端口。

也许有更好的方法来做我想做的事。我愿意接受建议。

node.js npm npm-scripts

2
推荐指数
1
解决办法
5196
查看次数