小编Ana*_*ali的帖子

如何使用ASP.NET标识在Web API 2中实现双因素身份验证?

我已经看到这个链接Two Factor Auth使用goolgle authenticator如何在web api中创建双因素身份验证,但我的要求略有不同.

  1. 我想使用双因素身份验证来发出访问令牌.(如果用户已选择启用双因素身份验证)
  2. 我想使用ASP.NET身份本身创建OTP代码.(就像我们在MVC Web应用程序中所做的那样SignInManager.SendTwoFactorCodeAsync("Phone Code")

我当前实现的问题是,当我调用时,SignInManager.SendTwoFactorCodeAsync("Phone Code")我得到错误用户ID未找到.

为了调试,我试着调用User.Identity.GetUserId();它返回正确的用户ID.

我检查了Microsoft.AspNet.Identity.Owin程序集的源代码

    public virtual async Task<bool> SendTwoFactorCodeAsync(string provider)
    {
        var userId = await GetVerifiedUserIdAsync().WithCurrentCulture();
        if (userId == null)
        {
            return false;
        }

        var token = await UserManager.GenerateTwoFactorTokenAsync(userId, provider).WithCurrentCulture();
        // See IdentityConfig.cs to plug in Email/SMS services to actually send the code
        await UserManager.NotifyTwoFactorTokenAsync(userId, provider, token).WithCurrentCulture();
        return true;
    }

    public async Task<TKey> GetVerifiedUserIdAsync()
    {
        var result = await AuthenticationManager.AuthenticateAsync(DefaultAuthenticationTypes.TwoFactorCookie).WithCurrentCulture();
        if (result != null …
Run Code Online (Sandbox Code Playgroud)

authentication one-time-password asp.net-web-api asp.net-identity

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

如何在WPF MVVM中单击此按钮?

我开始研究WFM MVVM模式.

但是我无法理解为什么这个Button点击不会绑定任何事件或动作.

视图

<Window x:Class="WPF2.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:vm="clr-namespace:WPF2.ViewModel"
    Title="MainWindow" Height="350" Width="525">

    <Window.Resources>
        <vm:MainWindowViewModel x:Key="MainViewModel" />
    </Window.Resources>

    <Grid x:Name="LayoutRoot"
          DataContext="{Binding Source={StaticResource MainViewModel}}">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
            <RowDefinition Height="Auto"/>
        </Grid.RowDefinitions>

        <TextBox Grid.Row="1" Height="23" HorizontalAlignment="Left" Margin="80,7,0,0" Name="txtID" VerticalAlignment="Top" Width="178" Text="{Binding ElementName=ListViewProducts,Path=SelectedItem.ProductId}" />
        <TextBox Grid.Row="1" Height="23" HorizontalAlignment="Left" Margin="80,35,0,0" Name="txtName" VerticalAlignment="Top" Width="178" Text="{Binding ElementName=ListViewProducts,Path=SelectedItem.Name}" />
        <TextBox Grid.Row="1" Height="23" HorizontalAlignment="Left" Margin="80,61,0,0" Name="txtPrice" VerticalAlignment="Top" Width="178" Text="{Binding ElementName=ListViewProducts,Path=SelectedItem.Price}" />
        <Label Content="ID" Grid.Row="1" HorizontalAlignment="Left" Margin="12,12,0,274" Name="label1" />
        <Label Content="Price" Grid.Row="1" Height="28" HorizontalAlignment="Left" Margin="12,59,0,0" Name="label2" VerticalAlignment="Top" …
Run Code Online (Sandbox Code Playgroud)

c# wpf button mvvm

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