小编Bjo*_*orn的帖子

没有密码的ASP.NET MVC Identity登录

我被赋予修改ASP.NET MVC应用程序的任务,以便冲浪到myurl?username = xxxxxx会自动登录用户xxxxxx,而不需要密码.

我已经非常清楚地表明,对于许多与安全相关的原因和情景来说,这是一个可怕的想法,但负责人是有决心的.该网站不会公开.

那么:有没有办法在没有密码的情况下登录,例如扩展Microsoft.AspNet.Identity.UserManager并修改AccountController?

一些代码:

  var user = await _userManager.FindAsync(model.UserName, model.Password);
                    if (user != null && IsAllowedToLoginIntoTheCurrentSite(user))
                    {
                        user = _genericRepository.LoadById<User>(user.Id);
                        if (user.Active)
                        {
                            await SignInAsync(user, model.RememberMe);
Run Code Online (Sandbox Code Playgroud)

_userManager包含Microsoft.AspNet.Identity.UserManager的实例.

和SignInAsync():

 private async Task SignInAsync(User user, bool isPersistent)
    {
        AuthenticationManager.SignOut(DefaultAuthenticationTypes.ExternalCookie);
        var identity = await _userManager.CreateIdentityAsync(user, DefaultAuthenticationTypes.ApplicationCookie);
        if (user.UserGroupId.IsSet())
            user.UserGroup = await _userManager.Load<UserGroup>(user.UserGroupId);

        //adding claims here ... //

        AuthenticationManager.SignIn(new AuthenticationProperties { IsPersistent = isPersistent }, new CustomClaimsIdentity(identity));
    }
Run Code Online (Sandbox Code Playgroud)

AuthenticationManager将是OwinSecurity.

c# asp.net-mvc password-protection

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

WPF运行时区域设置更改,重新评估ValueConverters UI

在大型WPF应用程序中,我们可以在运行时更改语言.我们使用WPF Localize Extension和resx文件进行本地化,除了UI中使用的转换器外,它工作得很好.如果在绑定中ValueConverter是特定于文化的,则不会在语言更改时更新生成的文本.

如何让WPF在应用程序范围内更新所有转换后的绑定?

编辑:目前我们已经通过制作ValueConverters MultiValueConverters并将区域设置添加为额外值进行了实验.这样,值源值会更改,并且结果会更新.但这很麻烦而且很难看.

<MultiBinding Converter="{StaticResource _codeMultiConverter}" ConverterParameter="ZSLOOPAKT">
  <Binding Path="ActivityCode" />
  <Binding Source="{x:Static lex:LocalizeDictionary.Instance}" Path="Culture" />
  <Binding Source="{x:Static RIEnums:CodeTypeInfo+CodeDisplayMode.Both}" />
</MultiBinding>
Run Code Online (Sandbox Code Playgroud)

相关: 绑定中的运行时文化更改和IValueConverter (我没有手动为每个字段提高propertychanged的选项)

c# data-binding wpf localization converter

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

Caliburn Micro Message.attach 不考虑数据上下文的变化

这是一个简化的例子。我有一个包含“浏览到文件夹”功能的用户控件,使用文本框和按钮。单击该按钮将打开浏览对话框,并基本上填充文本框。

<UserControl x:Class="MyUserControl"
         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
         xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
         xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
         xmlns:cal="http://www.caliburnproject.org"
         mc:Ignorable="d" 
         d:DesignHeight="300" d:DesignWidth="300">
<Grid>
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="100"></ColumnDefinition>
        <ColumnDefinition Width="*"></ColumnDefinition>
    </Grid.ColumnDefinitions>

    <Grid.RowDefinitions>
        <RowDefinition Height="Auto"></RowDefinition>
    </Grid.RowDefinitions>

    <!-- Folder -->
    <TextBlock>Path</TextBlock>
    <DockPanel LastChildFill="True" Grid.Column="1">
        <Button DockPanel.Dock="Right" cal:Message.Attach="[Event Click] = [Action BrowseHotFolder()]" Content="..." HorizontalAlignment="Left" Width="25" Height="25" VerticalContentAlignment="Center" HorizontalContentAlignment="Center" Margin="0,0,5,0"/>
        <TextBox Text="{Binding HotFolderPath, UpdateSourceTrigger=PropertyChanged, ValidatesOnNotifyDataErrors=True}"  />
    </DockPanel>
</Grid>
Run Code Online (Sandbox Code Playgroud)

我有一个包含许多对象的列表框。所选对象将作为数据上下文馈入此用户控件。

<Window>
   ...
   <Listbox ItemsSource="{Binding Items, Mode=OneWay}" SelectedItem="{Binding SelectedItem}">
   ...
   <view:MyUserControl DataContext="{Binding SelectedItem}" />
</Window>
Run Code Online (Sandbox Code Playgroud)

现在,假设我的列表框中有两个项目,并且我选择了第一个。我在 MyUserControl 的文本框中填写“foo”。然后我选择第二个项目,并填写“栏”。数据绑定工作正常,并且两个项目都设置了正确的值。如果我然后单击第一个上的浏览按钮并选择一个文件夹,它会将第一个项目的文本框更改为所选路径。但是,如果我选择第二项并浏览到一个文件夹,它也会更改第一项的文本框。

我的猜测是消息附加语法不会在正确的项目上调用浏览操作。它不考虑数据上下文(当前选择的项目)而只使用第一个。

我该怎么办?

wpf datacontext caliburn.micro

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