如何在 WPF 中使用 Windows 身份验证? [英] How to use Windows Authentication in WPF?

查看:29
本文介绍了如何在 WPF 中使用 Windows 身份验证?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我没有找到太多关于如何在 WPF 应用程序中使用 Windows 身份验证的文档.我不会认为它与任何非 WPF 应用程序有任何不同,但似乎确实如此.我想进入我的项目属性 ->应用程序并确保 Windows 身份验证已启用,但该选项在 WPF 应用程序中不可用(如以下文档所确认).

I'm not finding much documentation on how to use Windows Authentication in a WPF app. I wouldn't have thought that it would be any different than in any non-WPF app, but it seems that it is. I want to go into my project Properties -> Application and ensure that Windows Authentication is on, but that option is not available in a WPF app (as the following document confirms).

http://msdn.microsoft.com/en-us/library/tzdks800.aspx

如果我忽略所有这些而只查看 My.User.Name (VB),它是空的.这告诉我不知何故未启用 Windows 身份验证.

If I ignore all that and just look at My.User.Name (VB), it is empty. This tells me that somehow Windows Authentication is not enabled.

似乎有一个我遗漏的概念;有人能指出我正确的方向吗?

Seems like there is a concept I am missing; could someone point me in the right direction?

我的计划是使用 PrincipalPermissionAttribute 来限制对我应用的某些部分(或者可能是整个应用,通过将其应用于 Application_Startup())的访问.>

My plan is to use PrincipalPermissionAttribute to restrict access to certain parts of my app (or perhaps the entire app, by applying it to Application_Startup()).

推荐答案

Itowlson 的回答是正确的,但是,为了在任何方法上使用 PrincipalPermissionAttribute,您必须首先通过调用使 windows 主体成为当前主体:

Itowlson's answer is correct, but also, in order to use the PrincipalPermissionAttribute on any method, you have to first make the windows principal the current principal by calling:

AppDomain.CurrentDomain.SetPrincipalPolicy(PrincipalPolicy.WindowsPrincipal)

这篇关于如何在 WPF 中使用 Windows 身份验证?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆