我在Visual Studio 2013中调试时试图获取Windows用户名.我只是使用:
httpcontext.current.user.identity.name
Run Code Online (Sandbox Code Playgroud)
如果我在我的开发服务器上运行它,它工作正常,如果我在任何以前版本的Visual Studio上以调试模式运行它也可以正常工作.
我的问题是 - 如果我在visual studio 2013上运行它,我会得到一个空字符串.
我的网络配置如下.
<system.web>
<authentication mode="Windows"/>
<identity impersonate="false"/>
<authorization>
<allow users="*"/>
</authorization>
<compilation debug="true" strict="false" explicit="true" targetFramework="4.0"/>
<customErrors mode="Off"/>
</system.web>
Run Code Online (Sandbox Code Playgroud) web-config windows-authentication iis-express visual-studio-2013
我希望有人可以提供帮助.
我花了一些时间研究在开发通用应用程序时使用MVVM模式将事件绑定到ViewModel命令的最佳方法.我正在使用MVVM Light.作为测试我正在使用ComboBox的SelectionChanged事件.
我读过一些人从Windows 8.1/WinRT框架中捏了一下Behaviors SDK,并取得了一些成功.我还在我的项目中包含了Universal App behavior SDK并尝试了以下内容(从Windows 8.1示例中汇总但使用UWP SDK).
XAML
<Page
xmlns:interactivity="using:Microsoft.Xaml.Interactivity"
xmlns:core="using:Microsoft.Xaml.Interactions.Core" />
...
<ComboBox ItemsSource="{Binding InputQuantities}">
<interactivity:Interaction.Behaviors>
<core:EventTriggerBehavior EventName="SelectionChanged">
<core:InvokeCommandAction Command="{Binding SomeComboBoxCommand}" CommandParameter="Foo" />
</core:EventTriggerBehavior>
</interactivity:Interaction.Behaviors>
</ComboBox>
Run Code Online (Sandbox Code Playgroud)
查看模型
public RelayCommand SomeComboBoxCommand {get; set;}
Run Code Online (Sandbox Code Playgroud)
但是,核心:InvokeCommandAction不是Behaviors SDK的一部分,我得到无效类型:期望类型是'Microsoft.Xaml.Interactivity.ActionCollection'.我试过使用ActionCollection ....但我不确定我知道我在做什么.
我成功地使用了编译绑定并使用Laurent的 Blog Post:
XAML
<ComboBox ItemsSource="{Binding InputQuantities}" SelectionChanged="{x:Bind Vm.SomeComboBoxCommand }" />
Run Code Online (Sandbox Code Playgroud)
查看模型
public void SomeComboBoxCommand(object sender, SelectionChangedEventArgs e){//do stuff}
Run Code Online (Sandbox Code Playgroud)
我知道这不是Laurent打算在这里演示的内容,我认为这样做会破坏视图和VM的分离,然后必须引用视图模型中的UI组件来获取所选项.但我在研究过程中看到了这样做的参考.
那么如何使用Universal App交互行为来实现这一点,如果这是正确的方式呢?
更新1.
这是我试图添加,相信,错误地说我正在添加通用应用程序行为SDK.我当时没有注意到它是针对Windows 8.1的.
但是,我的问题仍然存在:为什么不InvokeActioncommand
工作,为什么会抛出上述错误?我上班后会立即查看其他帖子.
更新2 在我的工作PC上测试这个(完全相同的代码,第一个例子和相同的行为SDK)它工作正常,我得到了我期望的行为.我需要在家用电脑上再次测试,看看出了什么问题.(感谢Justin XL坚持我)
更新3 为了完整性,回国后我得到了我的项目的最新版本(从我的工作PC上检查),它现在也适用于我的家用电脑.我不确定我的Visual Studio处于什么状态,但是我已经足够混淆了我发布这个问题.至少这应该作为如何做标题中描述的内容的文件.感谢你的帮助.