小编Ale*_* A.的帖子

如何确认ASP.Net Core 1.1MVC中的电话号码

我无法弄清楚如何在asp.net核心1.1中进行电话号码确认

身份服务配置包含要求确认的电子邮件和/或电话号码的明确选项.

它可以通过以下方式完成:

services
    .AddIdentity<User, Role>(options =>
    {
        options.SignIn.RequireConfirmedEmail = true;
        options.SignIn.RequireConfirmedPhoneNumber = true;
     });
Run Code Online (Sandbox Code Playgroud)

由于UserManager包含显式令牌生成器及其验证器,因此电子邮件的验证非常简单:

var token = await _userManager.GenerateEmailConfirmationTokenAsync(user);
Run Code Online (Sandbox Code Playgroud)

生成的令牌可以通过以下方式验证:

var result = await _userManager.ConfirmEmailAsync(user, code);
Run Code Online (Sandbox Code Playgroud)

如果令牌有效,上面的行将把user.EmailConfirmed标志切换为true.

现在的问题是我没有看到类似的方法来生成电话验证令牌及其等效方法来验证它(如果成功,它应该将user.PhoneNumberConfirmed标志切换为true).

但是,用户管理器包含的用户手机更改方法很少:

_userManager.GenerateChangePhoneNumberTokenAsync();
Run Code Online (Sandbox Code Playgroud)

_userManager.VerifyChangePhoneNumberTokenAsync();
Run Code Online (Sandbox Code Playgroud)

但似乎这些方法不会切换user.PhoneNumberConfirmed标志.

我错过了什么吗?确认用户电话号码的正确方法是什么(换句话说,将user.PhoneNumberConfirmed设置为true)?

asp.net-core-mvc asp.net-core asp.net-core-identity

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

如何使用debian/linux上的Asp.Net Core 2上的证书保护数据保护密钥文件

我正在尝试配置数据保护并使用证书来保护密钥文件.以下是MS文档配置数据保护

这是我正在尝试做的事情:

services
    .AddDataProtection()
    .SetApplicationName("test server")
    .PersistKeysToFileSystem("/home/www-data/config")
    .ProtectKeysWithCertificate(
        new X509Certificate2("/home/www-data/config/"keyprotection.pfx);
Run Code Online (Sandbox Code Playgroud)

当我启动应用程序时,我在启动时收到以下错误:

info: Microsoft.AspNetCore.DataProtection.KeyManagement.XmlKeyManager[58]
    Creating key {71e2c23f-448b-49c9-984f-3c8d7227c904} with 
    creation date 2017-08-29 18:53:51Z, activation date 2017-08-29 18:53:51Z, and expiration date 2017-11-27 18:53:51Z.
info: Microsoft.AspNetCore.DataProtection.Repositories.FileSystemXmlRepository[39]
    Writing data to file '/home/www-data/config/key-71e2c23f-448b-49c9-984f-3c8d7227c904.xml'.
fail: Microsoft.AspNetCore.DataProtection.KeyManagement.XmlKeyManager[24]
    An exception occurred while processing the key element '<key id="71e2c23f-448b-49c9-984f-3c8d7227c904" version="1" />'.
System.Security.Cryptography.CryptographicException: Unable to retrieve the decryption key.
    at System.Security.Cryptography.Xml.EncryptedXml.GetDecryptionKey(EncryptedData encryptedData, String symmetricAlgorithmUri)
    at System.Security.Cryptography.Xml.EncryptedXml.DecryptDocument()
    at Microsoft.AspNetCore.DataProtection.XmlEncryption.EncryptedXmlDecryptor.Decrypt(XElement encryptedElement)
    at Microsoft.AspNetCore.DataProtection.XmlEncryption.XmlEncryptionExtensions.DecryptElement(XElement element, IActivator activator)
    at Microsoft.AspNetCore.DataProtection.KeyManagement.XmlKeyManager.Microsoft.AspNetCore.DataProtection.KeyManagement.Internal.IInternalXmlKeyManager.DeserializeDescriptorFromKeyElement(XElement keyElement)
warn: Microsoft.AspNetCore.DataProtection.KeyManagement.DefaultKeyResolver[12]
    Key …
Run Code Online (Sandbox Code Playgroud)

linux data-protection asp.net-core asp.net-core-2.0

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

有没有一种方法可以检查std :: future状态是否准备就绪,并且可以保证无等待?

我知道我可以std::future通过以下方式检查状态:

my_future.wait_for(std::chrono::seconds(0)) == std::future_status::ready

但是根据cppreference.com, std::future::wait_for在某些情况下可能会阻止:

由于调度或资源争用延迟,此功能可能阻塞的时间超过timeout_duration。

还是timeout_duration0 还是这样吗?如果是这样,是否还有另一种以保证免等待的方式查询状态的方法?

c++ multithreading c++11 std-future

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

如何将环境变量传递给 ExternalProject_Add CONFIGURE_COMMAND?

我有一个带有 autotools 项目的第三方库。我想使用 ExternalProject_Add 来构建库。

这可以通过以下方式完成:

ExternalProject_Add(project_lib
   SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/lib
   CONFIGURE_COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/lib/configure --prefix=${LIB_OUTPUT}
   BINARY_DIR ${CMAKE_CURRENT_SOURCE_DIR}/build
)
Run Code Online (Sandbox Code Playgroud)

现在的问题是我需要将环境变量传递给,configure但我找不到方法来做到这一点。

在控制台中,我会按照以下方式进行:

CPPFLAGS="-fPIC" ./configure --prefix=output

有没有办法将CPPFLAGS="-fPIC"env传递给configurewith ExternalProject_Add/CONFIGURE_COMMAND

build-automation build-process autotools cmake

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

std::forward 无限递归大小效应

考虑以下代码:

class Test
{
  public:
    Test()
    {
    }

    Test(const Test &other) noexcept
    {
        *this = other;
    }

    Test(Test &&other) noexcept
    {
        *this = std::move(other);
    }

    auto operator = (const Test &other) noexcept -> Test&
    {
        // Make a copy of "other"
        // ...
        return *this;
    }

    auto operator = (Test &&other) noexcept -> Test&
    {
        // Move "other"
        // ...
        return *this;
    }
};
Run Code Online (Sandbox Code Playgroud)

我想将移动和复制构造函数组合在一起。据我所知,可以像这样使用 std::forward 来实现:

template <class T>
Test(T &&other) noexcept
{
    *this = std::forward<T>(other);
}
Run Code Online (Sandbox Code Playgroud)

如果仔细使用,它看起来运行良好,如下所示:

Test …
Run Code Online (Sandbox Code Playgroud)

c++ c++11

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

“对象分配:LINQ方法调用”的含义

我使用 JetBrains Rider 进行 C# 编程。通常,Rider 会在我的代码中强调一些操作,例如以下list.WhereLINQ 方法调用:

在此处输入图片说明

当我将鼠标光标放在Where关键字上时,它会显示以下消息:

在此处输入图片说明

编译不会生成任何警告,Rider 本身也不会显示任何警告。但那又是什么意思呢?

c# rider

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