小编use*_*336的帖子

无法从根提供程序.Net Core 2解析范围服务

当我尝试运行我的应用程序时,我收到错误

InvalidOperationException: Cannot resolve 'API.Domain.Data.Repositories.IEmailRepository' from root provider because it requires scoped service 'API.Domain.Data.EmailRouterContext'.
Run Code Online (Sandbox Code Playgroud)

奇怪的是,这个EmailRepository和界面设置完全相同,因为我可以告诉所有其他存储库,但没有为它们抛出错误.只有在我尝试使用app.UseEmailingExceptionHandling()时才会出现错误; 线.这是我的一些Startup.cs文件.

public class Startup
{
    public IConfiguration Configuration { get; protected set; }
    private APIEnvironment _environment { get; set; }

    public Startup(IConfiguration configuration, IHostingEnvironment env)
    {
        Configuration = configuration;

        _environment = APIEnvironment.Development;
        if (env.IsProduction()) _environment = APIEnvironment.Production;
        if (env.IsStaging()) _environment = APIEnvironment.Staging;
    }

    public void ConfigureServices(IServiceCollection services)
    {
        var dataConnect = new DataConnect(_environment);

        services.AddDbContext<GeneralInfoContext>(opt => opt.UseSqlServer(dataConnect.GetConnectString(Database.GeneralInfo)));
        services.AddDbContext<EmailRouterContext>(opt => opt.UseSqlServer(dataConnect.GetConnectString(Database.EmailRouter)));

        services.AddWebEncoders();
        services.AddMvc();

        services.AddScoped<IGenInfoNoteRepository, GenInfoNoteRepository>();
        services.AddScoped<IEventLogRepository, EventLogRepository>(); …
Run Code Online (Sandbox Code Playgroud)

c# asp.net-core asp.net-core-2.0

53
推荐指数
5
解决办法
3万
查看次数

在ASP.NET Core 2.0中获取AuthenticationInfo

如何AuthenticationInfo从ASP.NET Core 2.0中的HttpContext 获取属性.我理解,随着ASP.NET Core 2.0中安全性的重新设计,AuthenticationManager现在已经过时,我应该删除.Authentication.

我曾经在1.1.2中做过类似的事情

var info = await httpContext.Authentication.GetAuthenticateInfoAsync("Automatic");
info.Properties.StoreTokens(new List<AuthenticationToken>
{
    new AuthenticationToken
    {
        Name = OpenIdConnectParameterNames.AccessToken,
        Value = accessToken
    },
    new AuthenticationToken
    {
        Name = OpenIdConnectParameterNames.RefreshToken,
        Value = refreshToken
    }
});

await httpContext.Authentication.SignInAsync("Automatic", info.Principal, info.Properties);
Run Code Online (Sandbox Code Playgroud)

c# asp.net-core

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

不记名令牌和 CSRF

我们正在使用 ASP.NET Core 构建 3 个不同的应用程序 MVC 应用程序、API、SPA(不是 Angular)。此应用程序中的所有操作仅适用于授权用户。这就是我们使用 IdentityServer 保护它们的原因。

我们使用 cookie 来存储不记名令牌的值。我知道 cookie 的值会自动发送到服务器。但是因为它应该作为授权标头添加,所以浏览器不会自动完成。

这是否降低了 CSRF 攻击的可能性?或者CSRF仍然可以使用不记名令牌,我们是否需要添加CSRF令牌?

asp.net-mvc csrf-protection openid-connect asp.net-core

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

失败的登录尝试

Identity Server 4 是否支持在多次登录尝试失败后暂停帐户?

我知道有更好的方法来处理失败的登录尝试,比如在用户最终成功登录时要求用户提供更多形式的身份证明。但是扩展 Identity Server 4 以在 x 次登录失败后暂停帐户是否足够容易,通过IP地址等?

identityserver4

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