小编MHO*_*OOS的帖子

升级到5.0.0后,TokenValidationParameters不再工作

我有以下代码,当我使用System.IdentityModel.Tokens.Jwt,Version = 4.0.20622.1351时,它正在工作

private static void ConfigureAzureAD(IAppBuilder appBuilder)
{
    appBuilder.UseWindowsAzureActiveDirectoryBearerAuthentication(
        new WindowsAzureActiveDirectoryBearerAuthenticationOptions
        {
            Tenant = ConfigurationManager.AppSettings["ida:Tenant"],
            TokenValidationParameters = new System.IdentityModel.Tokens.TokenValidationParameters
            {
                ValidAudience = ConfigurationManager.AppSettings["ida:Audience"]
            }
        });
}
Run Code Online (Sandbox Code Playgroud)

但是,只要我将此软件包升级到版本5的最新软件包,它就不再编译抱怨参考类型'TokenValidationParameters'声明它在System.IdentityModel.Token.Jwt中定义,但无法找到它.

此外,如果您尝试以下编译器将警告您Audience已过时:

 private static void ConfigureAzureAD(IAppBuilder appBuilder)
    {
        appBuilder.UseWindowsAzureActiveDirectoryBearerAuthentication(
            new WindowsAzureActiveDirectoryBearerAuthenticationOptions
            {
                Tenant = ConfigurationManager.AppSettings["ida:Tenant"],
                Audience = ConfigurationManager.AppSettings["ida:Audience"]
            });
    }
Run Code Online (Sandbox Code Playgroud)

我再次降级此DLL并使用版本4.0.20622.1351,它开始编译.

配置Azure Active Directory是否有语法更改?

在Github上,我找不到使用最新软件包5.0.0的单个项目,并且所有软件都使用之前的软件包4.0.20622.1351.任何人都可以使用最新的System.IdentityModel.Tokens.Jwt 5.0.0对此进行说明,或者使用最新的软件包将我引导到Github上的一些项目?

c# azure azure-web-sites azure-active-directory

54
推荐指数
4
解决办法
3万
查看次数

使用switch时,tslint抱怨"语句必须使用if语句进行过滤"

可以说我有以下方法:

getErrorMessage(state: any, thingName?: string) {
    const thing: string = state.path || thingName;
    const messages: string[] = [];
    if (state.errors) {
        for (const errorName in state.errors) {
            switch (errorName) {
                case 'required':
                    messages.push(`You must enter a ${thing}`);
                    break;
                case 'minlength':
                    messages.push(`A ${thing} must be at least ${state.errors['minlength'].requiredLength}characters`);
                    break;
                case 'pattern':
                    messages.push(`The ${thing} contains illegal characters`);
                    break;
                case 'validateCardNumberWithAlgo':
                    messages.push(`Card doesnt pass algo`);
                    break;
            }
        }
    }
    return messages;
}
Run Code Online (Sandbox Code Playgroud)

我跑的时候

ng lint
Run Code Online (Sandbox Code Playgroud)

我收到以下错误:

for(... in ...)语句必须使用if语句进行过滤

看一下类似的问题,我认为答案不适用于我的情况.所有switch语句都在if-else-if阶段的类别中.

tslint应该将switch语句视为if语句的形式,但它没有?!

typescript tslint angular-cli angular

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

如何持久化实现状态模式的对象?

我是状态设计模式的新手,我找不到将对象的不同状态保存到数据库的正确示例(在我的例子中是SQL Server).该场景与下一篇文章中描述的示例非常相似[几乎相同],但是我没有找到将状态持久保存到数据库的适用解决方案.你们可以推荐一个链接或者可能举个例子吗?

C#中的状态模式用法和示例

另外:如何在运行时枚举所有不同的ConcreteState类型?举例来说,如果你有10个不同的国家,你声明与10个不同成员的EnumStates,并给每一个成员的ConcreteState关联EnumStates成员,或者你通过得到的ConcreteState的子类得到所有的不同的状态?

为了您的信息,我需要能够根据不同的状态搜索实体.

c# state design-patterns software-design state-machine

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

为什么DbSet <TEntity>不实现EnumerableAsync

在实体框架6.1.1中,IDbSet表示可以从数据库查询的实体集合,其具体实现是DbSet,如

DbSet

为什么这个接口或其具体实现不包含ToEnumerableAsync或AsEnumerableAsync的任何定义,而是ToListAsync,ToArrayAsync,ToDictionaryAsync?

为了让您了解我遇到此问题的原因,我有以下一段代码,我希望将其设为异步:

public IQueryable<TEntity> GetQuery<TEntity>() where TEntity : class
{
    string entityName = GetEntityName<TEntity>();
    return ((IObjectContextAdapter)DbContext).ObjectContext.CreateQuery<TEntity>(entityName);
}


public IEnumerable<TEntity> Get<TEntity, TOrderBy>(Expression<Func<TEntity, TOrderBy>> orderBy, int pageIndex, int pageSize, SortOrder sortOrder = SortOrder.Ascending) where TEntity : class
{
    if (sortOrder == SortOrder.Ascending)
    {
        return GetQuery<TEntity>().OrderBy(orderBy).Skip((pageIndex - 1) * pageSize).Take(pageSize).AsEnumerable();
    }
    return
        GetQuery<TEntity>()
            .OrderByDescending(orderBy)
            .Skip((pageIndex - 1) * pageSize)
            .Take(pageSize)
            .AsEnumerable();
}
Run Code Online (Sandbox Code Playgroud)

我想到的唯一实现如下:

public async Task<IEnumerable<TEntity>> GetAsync<TEntity, TOrderBy>(Expression<Func<TEntity, TOrderBy>> orderBy, int pageIndex, int pageSize, SortOrder sortOrder = SortOrder.Ascending) where TEntity : …
Run Code Online (Sandbox Code Playgroud)

ienumerable entity-framework async-await c#-5.0 entity-framework-6

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

一次性进行多个数据库迁移

我的代码第一个项目中有四个不同的数据库,需要迁移.考虑以下 :

-- Enabling migrations
Enable-Migrations -StartUpProjectName SampleProject -MigrationsDirectory Migrations\DB1Configuration -ContextTypeName DB1ConfigurationDbContext -ContextAssemblyName SampleProject -ConnectionStringName MyDbContext1

Enable-Migrations -StartUpProjectName SampleProject -MigrationsDirectory Migrations\DB2Configuration -ContextTypeName DB2ConfigurationDbContext -ContextAssemblyName SampleProject -ConnectionStringName MyDbContext2

Enable-Migrations -StartUpProjectName SampleProject -MigrationsDirectory Migrations\DB3Configuration -ContextTypeName DB3ConfigurationDbContext -ContextAssemblyName SampleProject -ConnectionStringName MyDbContext3

Enable-Migrations -StartUpProjectName SampleProject -MigrationsDirectory Migrations\DB4Configuration -ContextTypeName DB4ConfigurationDbContext -ContextAssemblyName SampleProject -ConnectionStringName MyDbContext4

-- Addning migrations

Add-Migration -StartUpProjectName SampleProject -Name InitialCreate -ConfigurationTypeName SampleProject.Migrations.DB2Configuration.Configuration -ConnectionStringName MyDbContext1

Add-Migration -StartUpProjectName SampleProject -Name InitialCreate -ConfigurationTypeName SampleProject.Migrations.DB1Configuration.Configuration -ConnectionStringName MyDbContext2

Add-Migration -StartUpProjectName SampleProject -Name InitialCreate -ConfigurationTypeName SampleProject.Migrations.DB3Configuration.Configuration -ConnectionStringName MyDbContext3

Add-Migration …
Run Code Online (Sandbox Code Playgroud)

c# entity-framework nuget ef-migrations

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

过滤材料表中的不同列

我正在尝试向材质表添加不同的过滤器.更确切地说,我正在尝试重现类似于以下GIF的内容

图片描述

为此,我在以下Github线程中关注irowbin的响应,但根据他的指导原则,我无法真正生成我想要的内容

在Stackblitz或Github上有任何工作示例,所以我可以在mattable中关注并创建多个搜索过滤器吗?

material-design angular-material angular angular-material-5 angular-material-6

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

在Visual Studio 2017中隐藏生成的js文件

如何在解决方案资源管理器中隐藏生成的js文件(从Ts文件透明)?

可以说我有一个有角度的网站.我将此角度项目添加到Visual Studio(选择Visual Studio 2017 Enterprise作为我的代码编辑器).似乎没有直接的方法来隐藏这些生成的js文件.在Visual Studio中隐藏js文件建议的解决方案看起来非常粗糙.

我更像是一个类似于Visual Studio Code隐藏.js.map文件中建议的解决方案, 但它似乎只适用于VS代码.如何在Visual Studio中实现此目的?在哪里可以看到Visual Studio中添加的现有网站(角度项目)的工作空间相关设置?

visual-studio typescript visual-studio-2017

8
推荐指数
1
解决办法
1594
查看次数

在枚举中添加"Null"或"None"成员是一个好习惯吗?

在C#中创建新的枚举时,拥有null成员是一个好习惯吗?

如果是,默认情况下你给它的值是0吗?你会调用null成员Null还是NULL?你是否严格相信Null,或者你在调用null以外的东西时没有任何问题.例如无.你能详细说明你的答案吗?

.net c# null enums

7
推荐指数
2
解决办法
7532
查看次数

测试Web API网址的版本

对于我们的Web api项目,我们使用以下url版本控制系统:

HTTPS:// {FQDN}/{apiVersion}/{apiResourceName}/{resourcePath} {参数}?

例如,我们可以有如下内容:

https://myapi.mysite.com/v1/customer/2

现在考虑上面,假设您想要向客户发布两个版本(实时,测试).一个实时版本(使用实时数据),另一个是测试(使用测试数据进行客户开发测试).

对于直播,我可以轻松使用我提到的那个:https://myapi.mysite.com/v1/customer/2.

你如何命名上述api的测试版?什么是api url版本v1的测试版本?可以指定测试api url吗?

使用url版本控制时,API {fqdn}的完全限定域名的最佳做法是什么?

api rest restful-url restful-architecture asp.net-web-api

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

用于根据环境变量更新 config.json 的预构建脚本

我有一个 angular 9 应用程序,我在其中从资产文件夹中读取了 api url:

@Injectable()
export class ConfigService {

  private configUrl = '../../../assets/config/config.json';

  constructor(private loggerService: LoggerService) { }

  public async loadConfig(): Promise<any> {
    try {
      const response = await fetch(this.configUrl);

      if (!response.ok) {
        throw new Error(response.statusText);
      }

      return await response.json();
    } catch (err) {
      this.loggerService.error(`ConfigService 'loadConfig' threw an error on calling ${this.configUrl} : ${err.tostring()}`);
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

用于读取配置文件的方法在构建后配置角度生产文件中描述。

environment.ts

export const environment = {
  production: false,
  apiUrl: "https://localhost/api/",
};
Run Code Online (Sandbox Code Playgroud)

environment.prod.ts

export const environment = …
Run Code Online (Sandbox Code Playgroud)

typescript angular-cli angular angular9 angular-cli-v9

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