良好的登录页面模式 [英] Good login page pattern

查看:71
本文介绍了良好的登录页面模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序在启动时不需要登录,但要访问某些页面。因此,如果他们已经登录,它将直接进入该页面,但如果不是,我需要强制他们进入登录页面,一旦他们登录后将他们重定向回他们前往的
页面。

My application does not require a login on start up, however to access certain pages it does. So if they're logged in, it will go right to that page, but if not I need to force them to the login page, and once they're logged in redirect them back to the page they were headed for.

任何提示?

目前,在需要登录的页面中,我会覆盖它的OnNavigatedTo,就像这样......

Currently, in a page that requires login I'll override it's OnNavigatedTo like so...

protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            User user = ((App)App.Current).UserObject;
            if (user == null)
            {
                NavigationService.Navigate(new Uri(string.Format("/LoginPage.xaml?RedirectUri={0}", e.Uri), UriKind.Relative));
            }            

            base.OnNavigatedTo(e);

            if (!ViewModel.IsDataLoaded)            
                ViewModel.LoadData();            
        }

因此,您可以看到我将重定向URI作为导航调用中的参数传递。然后在登录页面上,在他们登录后我导航回原始URI。

So there you can see I pass the redirect URI as a parameter in the navigate call. Then on the login page, after they've logged in I navigate back to the original URI.

这似乎工作正常,但我无法弄清楚在哪里调用NavigationService.RemoveBackEntry ()以删除该登录页面。我试图把它放在任何地方都没有产生正确的结果。

This seems to work ok, but I can't figure out where to call NavigationService.RemoveBackEntry() in order to remove that login page. Everywhere I try to put it does not yield the proper results.

我希望通过在需要登录和处理一些全局OnNavigating的页面上放置一个接口,这是一种更清洁的方式。一些东西,但这似乎不可能(这是我的第一个WP应用程序)

I was hoping to do this is a cleaner way, by putting an interface on pages that require login and handling some global OnNavigating or something, but that doesn't seem to be possible (this is my first WP app)

无论如何,任何提示都将不胜感激!

Anyways, any tips would be appreciated!



谢谢!


Thanks!

推荐答案

请参阅
类似的主题

我使用VisualStateManager实现了一些应用程序。 因此,我只是将页面呈现在LoggedIn或NeedToLogin状态,而不是重定向,这可能有其自身的问题。 一旦成功登录,您可以执行任何操作,从状态之间的
转换到即时切换到新状态。

I have implemented a few apps using the VisualStateManager.  So rather than re-direct, which can have its own issues, I just present the page in either a LoggedIn or NeedToLogin state.  And once successfully logged in you can do anything from a nice transition between states to just switching instantly to the new state.


这篇关于良好的登录页面模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆