简体   繁体   中英

UWP: Calling Frame.Navigate() from a Page.OnNavigatedTo event

Into an Universal windows app I want to check user's authentication during page load, or after that an user as navigated to. This permits me to offer a navigation filtered by authorizations with a single page granularity.

For example, if an user didn't login and a page requires authentication, user has to be redirected to a login page.

The problem comes when I try navigate to an other page from the OnNavigatedTo event, when previous navigation is not completed and the new fails. I've searched for other events like an OnNavigationCompleted , but I don't find anything. If I use an asynchronous method without waiting it works, as if I use a timer dispatcher, but both solutions doesn't sound like so clean.

Exists a method to handle an event raised after navigation completed or I have to pre-check authorization during navigation call? I hope to avoid this solution because a wrong call could show an unauthorized page.

If you really want a separate page according to this answer https://stackoverflow.com/a/19527979/4788286 you could probably use the loaded event. But I'd test it before just to make sure.

Sidenote: also, your question implies that you're doing business logic in the view codebehinds - this is bad practice, I suggest looking into the MVVM pattern. (If you need a framework I suggest MVVMLight or PRISM)

I think the precheck would be the best method. Check if they are authorized to view the page before they can navigate to the page. If they are not authorized ask if they want to log in or purchase rights to the page

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM