Silverlight Navigation Framework and Authentication
The Silverlight Navigation frameworks allows application developers to use URLs as shortcuts to specific screens within an application. (This idea of using URLs as a pointer to a specific application resource is not foreign to a web developer, but is certainly a new concept for most application developers).
However, it is the responsibility of the developer to ensure that users have sufficient permissions to view the screens.
This can be enforced by doing authorization checks in the OnNavigatedTo handler. (These examples use the Silverlight WCF RIA Services).
// Executes when the user navigates to this page.
protected override void OnNavigatedTo(NavigationEventArgs e)
{
if (WebContext.Current.User.IsAuthenticated)
{
FillDataGrid();
}
else
{
LoginRegistrationWindow loginWindow = new LoginRegistrationWindow();
loginWindow.Show();
}
}
In addition, the developer has to make sure that when authentication state changes, the screen is re-queried with the correct data.
public partial class CustomersPage : Page
{
public CustomersPage()
{
InitializeComponent();
WebContext.Current.Authentication.LoggedIn += new EventHandler(Authentication_LoggedIn);
WebContext.Current.Authentication.LoggedOut += new EventHandler(Authentication_LoggedOut);
}
void Authentication_LoggedIn(object sender, System.Windows.Ria.ApplicationServices.AuthenticationEventArgs e)
{
FillDataGrid();
}
void Authentication_LoggedOut(object sender, System.Windows.Ria.ApplicationServices.AuthenticationEventArgs e)
{
DataGridCustomer.ItemsSource = null;
}
}
Developers should unhook the event handlers when navigating away from the page.
protected override void OnNavigatingFrom(NavigatingCancelEventArgs e)
{
base.OnNavigatingFrom(e);
WebContext.Current.Authentication.LoggedIn -= new EventHandler(Authentication_LoggedIn);
WebContext.Current.Authentication.LoggedOut -= new EventHandler(Authentication_LoggedOut);
}
Altogether, the code is short and simple. However, a developer may wish to refactor the common elements (event handlers, showing logon screens etc) into a subclass of Windows.System.Controls.Page.
About this entry
You’re currently reading “ Silverlight Navigation Framework and Authentication ,” an entry on Chui's Counterpoint
- Published:
- 4.6.10 / 11pm
- Category:
- .Net
No comments
Jump to comment form | comments rss [?] | trackback uri [?]