Login and Logout Page Navigation in Silverlight 4


Introduction

In this article we will see how we can navigate to a default page when user logs out in Silverlight 4 navigation framework.

Image1.gif


Create Silverlight Application

Fire up Visual Studio 2010, and select Silverlight Business Application Project from the templates. Name the solution as NavigationSample2.

Image2.gif

Let's talk about requirements; a particular link should not be visible if a user is not logged in and as soon as user logs out the link should not be visible. And the user would be navigated to the Home page if logged out.

The above requirement is pretty simple. To achieve this let's add a page called EmployeePage.xaml to the View.

Image3.gif

Now add the link of the EmployeePage to the MainPage.xaml.

Image4.gif

As you see in the above xaml display, the visibility of the Hyperlink Button is made collapsed.

Now we would handle the LoggedIn and LoggedOut events of the RIA Authentication.

In MainPage.xaml.cs, we need to add the following in the constructor to achieve our requirement.

Image5.gif

As you see in the above Constructor, we have handled the Visibility of the link button based on the Authentication.
If we run the application we can see the changes.

Image6.gif

The above links are displayed when user hasn't logged in.

Image7.gif

The above links are displayed when user logs in.

Now we would do the second part of the requirement, which is if user logs out it would navigate to the Home Page.

As you can see in our requirement "EmployeePage" is the restricted Page and restricted Link and other links are public. So we would handle the LoggedOut event in EmployeePage's constructor.

Image8.gif

As you see in the above code, it's very simple. We need to navigate to the required page when user logs out.
Hope this article helps.
 

Up Next
    Ebook Download
    View all
    Learn
    View all