Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use Windows Authentication in 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

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?

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()).

like image 955
Patrick Szalapski Avatar asked Oct 05 '09 18:10

Patrick Szalapski


1 Answers

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)
like image 85
Patrick Szalapski Avatar answered Sep 24 '22 05:09

Patrick Szalapski