Skip to main content

Microsoft Silverlight

Answered Question Change Page on LogoutRSS Feed

(0)

silverlightmonster
silverli...

Member

Member

11 points

92 Posts

Change Page on Logout

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
esite

Participant

Participant

1452 points

311 Posts

Re: Change Page on Logout

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))   
 

Please mark replies as answers if they answered your question.

Anton Swanevelder
eSite Solutions

Sergey.Lutay
Sergey.L...

Contributor

Contributor

7256 points

1,354 Posts

Re: Change Page on Logout

Hi,

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.

(If this has answered your question, please click on "mark as answer" on this post. Thank you!)

Blog

Twitter

Sincerely,
Sergey Lutay

esite
esite

Participant

Participant

1452 points

311 Posts

Re: Change Page on Logout

 

navFrame.Navigate(new Uri("/view/Home.xaml", UriKind.Relative))
 

Please mark replies as answers if they answered your question.

Anton Swanevelder
eSite Solutions

MComeauS2S
MComeauS2S

Member

Member

284 points

155 Posts

Re: Change Page on Logout

If you're using the RiaContext, in your MainPage constructor:

RiaContext.Authentication.LoggedOut += Authentication_LoggedOut;

then just handle the event:

void Authentication_LoggedOut(object sender, AuthenticationEventArgs e)
{
   
if (ContentFrame.Source.OriginalString != "/Home")
        ContentFrame.Navigate(
new Uri("/Home", UriKind.Relative));
}

The actual URI depends on how you have setup your mainpage navigation frame and especially the UriMapper, here's mine

<navigation:Frame x:Name="ContentFrame" Style="{StaticResource ContentFrameStyle}" Source="/Home" Navigated="ContentFrame_Navigated" NavigationFailed="ContentFrame_NavigationFailed">
   
<navigation:Frame.UriMapper>
       
<uriMapper:UriMapper>
           
<uriMapper:UriMapping Uri="" MappedUri="/Views/Home.xaml"/>
           
<uriMapper:UriMapping Uri="/User/{IdUser}" MappedUri="/Views/User.xaml?IdUser={IdUser}" />
           
<uriMapper:UriMapping Uri="/Client/{IdUser}" MappedUri="/Views/Client.xaml?IdClient={IdUser}" />
           
<uriMapper:UriMapping Uri="/{pageName}" MappedUri="/Views/{pageName}.xaml"/>
       
</uriMapper:UriMapper>
    
</navigation:Frame.UriMapper>
</navigation:Frame>

hope this helps.

 

silverlightmonster
silverli...

Member

Member

11 points

92 Posts

Re: Change Page on Logout

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

silverlightmonster
silverli...

Member

Member

11 points

92 Posts

Re: Change Page on Logout

Please help! anyone any ideas?

Thanks

MComeauS2S
MComeauS2S

Member

Member

284 points

155 Posts

Re: Change Page on Logout

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( ..... )

 

silverlightmonster
silverli...

Member

Member

11 points

92 Posts

Re: Change Page on Logout

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?

MComeauS2S
MComeauS2S

Member

Member

284 points

155 Posts

Re: Change Page on Logout

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));
}
 

MComeauS2S
MComeauS2S

Member

Member

284 points

155 Posts

Re: Change Page on Logout

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.

silverlightmonster
silverli...

Member

Member

11 points

92 Posts

Re: Re: Change Page on Logout

is it possible from a file inside the Views folder, to somehow call the ContentFrame frame inside the MainPage.xaml in the root folder?

MComeauS2S
MComeauS2S

Member

Member

284 points

155 Posts

Re: Re: Change Page on Logout

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
acidburner

Member

Member

156 points

78 Posts

Re: Re: Re: Change Page on Logout

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:

//Keep an instance of the mainpage in app.xaml to access it from any control

public MainPage Mainpage

{

get

{

return (MainPage)this.RootVisual;

}

}

silverlightmonster
silverli...

Member

Member

11 points

92 Posts

Re: Re: Re: Change Page on Logout

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!

MComeauS2S
MComeauS2S

Member

Member

284 points

155 Posts

Answered Question

Re: Re: Re: Change Page on Logout

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(.......)

  • Unanswered Question
  • Answered Question
  • Announcement
Microsoft Communities