Reputation: 7506
In my web application I need to take different actions depending on the type of authentication used. The application is designed and build to support both windows and forms authentication and the switching between the two is done directly from IIS.
At the moment I check if, at the start of the session, the name of the user is stored in HttpContext.Current.User.Identity.Name
. If the Name
property is empty, then forms authentication is used; if not, then the property holds the name of the currently logged in winuser.
Is there a better way of dynamically checking the type of authentication used?
Upvotes: 1
Views: 2177
Reputation: 239694
You can check what type of principal HttpContext.Current.User
is returning. If windows authentication is being used (directly) then it should be a WindowsPrincipal
as opposed to a GenericPrincipal
(which is, I believe, what Forms Authentication will set up).
If you're supporting more complex authentication schemes (e.g. ADFS) then it'll probably just be some other form of ClaimsPrincipal
(which both of the above derive from).
Upvotes: 4
Reputation: 11026
You can check the value returned by the property FormsAuthentication.IsEnabled.
Upvotes: 2