Login and Logout Page Navigation In Silverlight 4
In this article we will see how we can navigate to a default page when user logs out in Silverlight 4 navigation framework.
Create Silverlight Application
Fire up Visual Studio 2010, and select Silverlight Business Application Project from the templates. Name the solution as NavigationSample2.
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.
Now add the link of the EmployeePage to the MainPage.xaml.
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.
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.
The above links are displayed when user hasn’t logged in.
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.
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.