rreeves
rreeves

Reputation: 2458

Making App Aware of Authentication

I have a c# Application where I call a user control with a click event. This user control provides the authentication to a MySQL database.

I dont want them to be able to use any of the other controls if they did not authenticate.

How can I make the rest of the Application aware that this user is authenticated. Can I somehow set a property in the main window ?

Upvotes: 2

Views: 119

Answers (3)

usr
usr

Reputation: 171246

You can put everything that should not be accessible inside of an invisible Panel and disable it. This will also disable all children.

Upvotes: 1

paparazzo
paparazzo

Reputation: 45106

Consider a separate logon page and not allow them access to the application Page / Window at all until there is a successful logon. In the constructor of the other pages just block them if the user is not authenticated. I have not used MemebershipServices in WPF but in ASP.NET it is clean with page level authority based on authenticated and even by Role. You can use App.cs for your global variables / properties.

Upvotes: 1

John
John

Reputation: 6553

You could bind the IsEnabled (or similar) properties of the controls to an IsAuthenticated Property of the Window / ViewModel. This would be the simplest because then you don't have to manually set the properties and just set the IsAuthenticated value to true / false.

The other option would be to manually set all of the IsEnabled to true / false depending on if authentication worked.

Upvotes: 1

Related Questions