小编Orc*_*usZ的帖子

Asp.net核心2 - 401错误与承载令牌

我无法使用Asp.net Core生成的令牌使用Authorized访问受保护的方法.

配置:

services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
            .AddJwtBearer(cfg =>
            {
                cfg.RequireHttpsMetadata = false;
                cfg.SaveToken = true;
                cfg.Audience = Configuration["Tokens:Issuer"];
                cfg.ClaimsIssuer = Configuration["Tokens:Issuer"];
                cfg.TokenValidationParameters = new TokenValidationParameters()
                {
                    ValidateIssuer = true,
                    ValidateAudience = true,
                    ValidateLifetime = true,
                    ValidateIssuerSigningKey = true,
                    ValidIssuer = Configuration["Tokens:Issuer"],
                    ValidAudience = Configuration["Tokens:Issuer"],
                    IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(Configuration["Tokens:Key"]))
                };
Run Code Online (Sandbox Code Playgroud)

生成的令牌:

var claims = new[] {
                new Claim (JwtRegisteredClaimNames.Sub, model.Email),
                new Claim (JwtRegisteredClaimNames.Jti, Guid.NewGuid ().ToString()),
            };

            //_config
            var key = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(_config["Tokens:Key"]));
            var creds = new SigningCredentials(key, SecurityAlgorithms.HmacSha256);
            var expiration = DateTime.UtcNow.AddDays(7);
            var …
Run Code Online (Sandbox Code Playgroud)

c# bearer-token asp.net-core

12
推荐指数
2
解决办法
5795
查看次数

Asp.net核心本地化与json文件

我正在努力寻找一个关于asp.net本地化的好教程.在官方文档中,解释是关于.resx文件,我想使用json文件.

如果有人有一个很好的教程,如何编写中间件来做到这一点.

谢谢

c# asp.net json localization asp.net-core

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

使用 NET Core 和 EF Core 构建谓词

非常快的问题:

我正在尝试创建一个这样的谓词构建器:

    var predicate = PredicateBuilder.False<MyObject>();
Run Code Online (Sandbox Code Playgroud)

但似乎在Net CoreEF Core 中不可用。

我是否缺少包裹或其他东西?

entity-framework-core asp.net-core

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

EF - context.Set&lt;t&gt; 与 context.T

自一个月以来,我想知道使用context.Set 与 context.T而不是语法有什么区别。

我用这个快速代码来说明这个问题,该代码试图从 EF 上下文的用户表信息中获取用户名。

context.Set 方法

context.Set<User>().Where(u => u.Id = userId).Select(u => u.UserName).Single();
Run Code Online (Sandbox Code Playgroud)

context.T 方法

 context.Users.Where(u => u.Id = userId).Select(u => u.UserName).Single();
Run Code Online (Sandbox Code Playgroud)

谢谢 :)

c# entity-framework

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

如何从npm安装Google-Recaptcha

我正在以某种形式在我的web应用程序中实现recaptcha。

我已经实现了后端部分,现在正在尝试安装recapatcha api。

不幸的是,我在Google的npm中找不到官方软件包。

我应该使用包含recpatcha的googleapis软件包还是应该包含以下脚本:

 <script src="https://www.google.com/recaptcha/api.js" async defer></script>
Run Code Online (Sandbox Code Playgroud)

我之所以这样问是因为我使用Webpack构建了脚本文件(包括来自npm的所有供应商)。

google-api recaptcha npm

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

多个onpopstate事件

我需要使用History API来处理应用程序.我的问题是一些"home"jQuery插件已经为popstate实现了一个事件

一个独特的视图可以有多个popstate事件?

javascript html5 html5-history

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

TypeScript中包含不同对象的数组

在从同一个类继承的一个数组中收集各种不同的对象时,如何在TypeScript中设置一个优等的类,以便TypeScript不显示错误?

我正在尝试这样:

interface IVehicle{
    modelName: string
}

interface ICar extends IVehicle{
    numberOfDoors: number,
    isDropTop: boolean
}

interface IBike extends IVehicle{
    hasDynamo: boolean
}


var vehicles: IVehicle[] =
    [
        {
            modelName: "carModelName", // Error
            numberOfDoors: 4,
            isDropTop: true
        },
        {
            modelName: "bikeModelName",
            hasDynamo: true
        }
    ]
Run Code Online (Sandbox Code Playgroud)

这样做,我遇到了错误.

IVehicle如果我不想显示任何错误,我只能添加上级界面的对象.

javascript typescript

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

模糊的项目名称 nuget:appveyor

我有一个 nuget 包,我在我的主分支上构建或发布一个版本。

问题是,只有在 appveyor 我有:

Restoring packages for C:\projects\askmethat-xforms-controls\src\Askmethat.XForms.Controls.NuGet\Askmethat.XForms.Controls.NuGet.nuproj...
nuget : Ambiguous project name 'Askmethat.XForms.Controls'.
At line:1 char:1
+ nuget restore .\src\Askmethat.XForms.Controls.sln
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (Ambiguous proje...orms.Controls'.:String) [], RemoteException
    + FullyQualifiedErrorId : NativeCommandError

Command executed with exception: Ambiguous project name 'Askmethat.XForms.Controls'.
Run Code Online (Sandbox Code Playgroud)

当我尝试恢复 nuget 项目的 nuget 包时会发生此错误。

这是最后一次构建:

https://ci.appveyor.com/project/AlexTeixeira/askmethat-xforms-controls/build/1.1.1-CI-11-bfnthmbj

这是 Github 中的项目:

https://github.com/AlexTeixeira/Askmethat-XForms-Controls/tree/master/src

我认为错误来自项目 Forms (一个网络标准库)。

如果我有这个项目的包 ID,恢复不会失败,但我的 nuget 包依赖于这个包 ID...

当然,一切都在我的机器上完美运行:最新的 macOs。

c# nuget appveyor

3
推荐指数
1
解决办法
1402
查看次数

在 EF Core 中添加迁移时出现“实体类型‘CustomAttributeData’需要定义主键”错误

我把我的模型放在一个带有 Core 的类库中。我已经进行了第一次迁移来测试我的模型的一部分,但是在进行了很大的增强之后,我删除了我的数据库和迁移,只有一个 V1 迁移。

问题是,在删除之后,当我尝试出现add-migration此错误时:

System.InvalidOperationException: The entity type 'CustomAttributeData' requires a primary key to be defined.
   at Microsoft.EntityFrameworkCore.Internal.ModelValidator.ShowError(String message)
   at Microsoft.EntityFrameworkCore.Internal.ModelValidator.Validate(IModel model)
   at Microsoft.EntityFrameworkCore.Internal.RelationalModelValidator.Validate(IModel model)
   at Microsoft.EntityFrameworkCore.Infrastructure.ModelSource.CreateModel(DbContext context, IConventionSetBuilder conventionSetBuilder, IModelValidator validator)
   at System.Collections.Concurrent.ConcurrentDictionary`2.GetOrAdd(TKey key, Func`2 valueFactory)
   at Microsoft.EntityFrameworkCore.Internal.DbContextServices.CreateModel()
   at Microsoft.EntityFrameworkCore.Internal.LazyRef`1.get_Value()
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitScoped(ScopedCallSite scopedCallSite, ServiceProvider provider)
   at Microsoft.Extensions.DependencyInjection.ServiceProvider.<>c__DisplayClass16_0.<RealizeService>b__0(ServiceProvider provider)
   at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetService[T](IServiceProvider provider)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitTransient(TransientCallSite transientCallSite, ServiceProvider provider)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitConstructor(ConstructorCallSite constructorCallSite, ServiceProvider provider)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitTransient(TransientCallSite transientCallSite, ServiceProvider provider)
   at Microsoft.Extensions.DependencyInjection.ServiceProvider.<>c__DisplayClass16_0.<RealizeService>b__0(ServiceProvider provider)
   at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService(IServiceProvider provider, Type serviceType)
   at …
Run Code Online (Sandbox Code Playgroud)

c# ef-code-first entity-framework-core asp.net-core

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

ASP.NET Core 2-文件未发布

编辑

有关信息,我正在使用VS Code在macOS上进行开发

我正在尝试在发布过程中包括文件(当前cshtml代表我的电子邮件模板)。

我在github上关注了这个线程,但似乎他们的解决方案对我不起作用。

在这里我的csproj添加一个唯一的cshtml文件:

  <Target Name="PrepublishScript" BeforeTargets="PrepareForPublish">
    <ItemGroup>
      <EmailFile Include="$(ProjectDir)/EmailTemplates/OrderCompleteEmail.cshtml" />
    </ItemGroup>
    <Copy SourceFiles="@(EmailFile)" DestinationFolder="$(PublishDir)" SkipUnchangedFiles="false" />
  </Target>
Run Code Online (Sandbox Code Playgroud)

c# csproj asp.net-core

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

Angular-使用asp.net Core Spa的多个环境

我正在尝试使用dotnet核心构建Angular SPA应用程序,该应用程序尝试根据buid定义名称使用特定的npm命令来构建angular 。

条件在我的csproj中具有最后2个目标。

<Project Sdk="Microsoft.NET.Sdk.Web">

  <PropertyGroup>
    <TargetFramework>netcoreapp2.1</TargetFramework>
    <TypeScriptCompileBlocked>true</TypeScriptCompileBlocked>
    <TypeScriptToolsVersion>Latest</TypeScriptToolsVersion>
    <IsPackable>false</IsPackable>
    <SpaRoot>ClientApp\</SpaRoot>
    <DefaultItemExcludes>$(DefaultItemExcludes);$(SpaRoot)node_modules\**</DefaultItemExcludes>

    <!-- Set this to true if you enable server-side prerendering -->
    <BuildServerSideRenderer>false</BuildServerSideRenderer>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.AspNetCore.App" Version="2.1.1"/>
    <PackageReference Include="Microsoft.AspNetCore.SpaServices.Extensions" Version="2.1.1" />
    <PackageReference Include="Gardendynamics.Commons" Version="1.0.0-ci-88" />
    <PackageReference Include="Gardendynamics.Tiers" Version="1.0.0-ci-50" />
  </ItemGroup>

  <ItemGroup>
    <ProjectReference Include="..\PicaplantBack.Database\PicaplantBack.Database.csproj" IncludeAssets="All" />
  </ItemGroup>
  <ItemGroup>
    <!-- Don't publish the SPA source files, but do show them in the project files list -->
    <Content Remove="$(SpaRoot)**" />
    <None Include="$(SpaRoot)**" Exclude="$(SpaRoot)node_modules\**" />
  </ItemGroup>

  <Target Name="DebugEnsureNodeEnv" BeforeTargets="Build" …
Run Code Online (Sandbox Code Playgroud)

asp.net-core angular

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