Skip to main content
Home Forums Silverlight Programming Silverlight Controls and Silverlight Toolkit Change Page on Logout
15 replies. Latest Post by MComeauS2S on November 5, 2009.
(0)
silverli...
Member
11 points
92 Posts
11-03-2009 8:32 AM |
Hi,
I am using a Silverlight Business project and need a behaviour so that when a user logs out, I take him to the homepage.
Can anyone tell me what is the exact command to be used to take the user to the home.xaml page?
In ASP.Net it's response.redirect("home.aspx") -> what is the silverlight equivalent of this?
Thanks!
esite
Participant
1452 points
311 Posts
11-03-2009 8:45 AM |
If you using the Silverlight Business project then your are probably using the NavigationControl, do something like this:
navFrame.Navigate(New Uri(Home.Tag, UriKind.Relative))
Sergey.L...
Contributor
7256 points
1,354 Posts
11-03-2009 8:46 AM |
For open some page use Navigate method of Frame class. It is not an alternative for Response.Redirect(...). But you can open new page of Silverlight application with it.
navFrame.Navigate(new Uri("/view/Home.xaml", UriKind.Relative))
MComeauS2S
284 points
155 Posts
11-03-2009 11:15 AM |
If you're using the RiaContext, in your MainPage constructor:
RiaContext.Authentication.LoggedOut += Authentication_LoggedOut;
then just handle the event:
hope this helps.
11-03-2009 4:07 PM |
Hi All,
I tried what MComeauS2 said but im getting an error: Name 'ContentFrame' is not declared. However, the frame where my content is being display is named Content Frame.
The issue is that the views (from where i am calling this function) reside in the Views folder while the MainPage.xaml is in the root folder.
Can anyone tell me how to solve this please?
Thanks
11-04-2009 10:53 AM |
Please help! anyone any ideas?
11-04-2009 1:08 PM |
use the name you give your Content Frame using x:Name ... that's the important part !
so, if the Content Frame has x:Name="JIMMY" the you do JIMMY.Navigate( ..... )
11-04-2009 1:16 PM |
Hi that is what I did. My frame is called ContentFrame. However, the page containing the content frame is in the root directory, and the frame where I am calling the method ContentFrame.Navigate(...) is located in a folder Views.
Does this make any difference since they are located in a different folder?
11-04-2009 1:32 PM |
Why not handle Logout at the MainPage level ?
The Code i posted earlier was suggesting that you handle the logout event from RiaContext.Authentication in the MainPage, i believe that it would be the best from to handle it. And from there you have access to ContentFrame.
Check this code, it comes from my MainPage:
public MainPage() { InitializeComponent(); this.loginContainer.Child = new LoginControl(); RiaContext.Current.Authentication.LoadUser(); RiaContext.Current.Authentication.LoggedOut += Authentication_LoggedOut; } void Authentication_LoggedOut(object sender, AuthenticationEventArgs e) { if (ContentFrame.Source.OriginalString != "/Home") ContentFrame.Navigate(new Uri("/Home", UriKind.Relative)); }
11-04-2009 1:37 PM |
silverlightmonster: Hi that is what I did. My frame is called ContentFrame. However, the page containing the content frame is in the root directory, and the frame where I am calling the method ContentFrame.Navigate(...) is located in a folder Views. Does this make any difference since they are located in a different folder?
Remember the UriMappings inside the ContentFrame are meant to select the right content for you. In essence, it allows you to map "/MyView" to "/Views/MyLatestView.xaml" or like "/MyView/[Id]" to "/Views/LasterView.xaml?viewid=[id]" or anything you like.
11-04-2009 1:58 PM |
is it possible from a file inside the Views folder, to somehow call the ContentFrame frame inside the MainPage.xaml in the root folder?
11-04-2009 6:37 PM |
Sure, make you ContentFrame available globally (or staticly) like:
public class MainPage{ public static TypeOfContentFrame MyContentFrame = null; public MainPage() { InitComponents(); MyContentFrame = ContentFrame; ... }}This is just to show .. i'm sure you can figure out the rest !
acidburner
156 points
78 Posts
11-05-2009 5:18 AM |
You can access the mainpage from the subpages by keeping an instance of the mainpage.
You can achive this by adding this to your app.xaml:
{
}
11-05-2009 3:45 PM |
Unfortunately i did not manage to do this :s
@MComeauS2S: public static TypeOfContentFrame MyContentFrame = null; - What type of content frames are available? I am using the default setting.. not so knowledgeable about this
@AcidBurner: I added this in my app behind code, though i still was not able to reference to it :(
Please help!
11-05-2009 3:54 PM |
sorry, couldnt gather the type when i wrote the post
its System.Windows.Controls.Frame
if you have a "using System.Windows.Controls" .. then just use Frame
you should be able to access public static members easily, format is ClassName.StaticMember
so, from your logout handler code, you can do (based on my provided sample) MainPage.MyContentFrame.Navigate(.......)