Silverlight 导航和身份验证服务

发布于 2024-07-21 22:24:23 字数 1216 浏览 2 评论 0原文

我正在使用导航应用程序模板创建一个银光应用程序。 它供内部使用,因此使用 Windows 身份验证。 有一个仪表板页面,显示了按登录用户 ID 过滤的几条记录。 为了获取用户 ID(这是一个 int),我通过重写 GetAuthenticatedUser 并传递用户名(来自 IPrincipal)来调用 Web 服务。 此服务需要一些时间才能返回详细信息。

当我导航到仪表板应用程序时,它完全渲染,没有数据,因为用户服务是异步操作,我无法让渲染等到我的 GetAuthenticatedUser 完全完成。 因此,我创建了一个登录页面,该页面仅显示进度条,直到获得用户对象,然后导航到仪表板。 如果有人尝试使用 URL 直接访问仪表板,我希望他们导航回登录页面。

因此,在仪表板构造函数中,我添加了以下代码,

        if (!UserService.Current.User.IsAuthenticated)
        {
            MessageBox.Show("Navigating away");
            Frame objContainer = this.Parent as Frame;
            objContainer.Navigate(new Uri("/Views/Login.xaml", UriKind.Relative));
        }

虽然我收到消息框提示,但它实际上并没有带我进入登录页面,而是停留在仪表板页面中。 我还尝试将此代码放入 OnNavigedTo 覆盖中,但没有成功。

我还尝试使用 NavigationService 而不是 Frame,如下所示,但不幸的是

        if (!UserService.Current.User.IsAuthenticated)
        {
            MessageBox.Show("Navigating away");
            this.NavigationService.Navigate(new Uri("/Views/Login.xaml", UriKind.Relative));
        }

它仍然无法工作。 有谁知道如何仅在我拥有完全有效的用户对象时才能访问某些页面? 如果他们尝试在没有此功能的情况下访问受限页面,我希望他们能够重定向到登录页面,这如何实现?

我正在使用 Silverlight 3 Beta

Shreedhar

I am creating a silver light application using Navigation app template. It is for internal use and hence uses windows authenticatoin. There is a dashboard page which shows couple of records filtered by logged in users id. To get the user id (which is an int) I call a web service by overriding the GetAuthenticatedUser and pass the username (from IPrincipal). This service takes some time to return the details.

When I navigate to dashboard app, it renders completely with no data because the user service is a async operation and I am not able to make the rendering wait till my GetAuthenticatedUser finishes completely. So I created a Login page which just shows a progress bar till I get the user object and then navigate to dashboard. If someone tries to access the dashboard directly by using the URL, i want them to navigate back to Login page.

So in the dashboard constructor I added the following code

        if (!UserService.Current.User.IsAuthenticated)
        {
            MessageBox.Show("Navigating away");
            Frame objContainer = this.Parent as Frame;
            objContainer.Navigate(new Uri("/Views/Login.xaml", UriKind.Relative));
        }

Thogh I get the message box prompt, it does not actually take me to Login page but stays in dashboard page. I also tried putting this code in OnNavigatedTo override with no luck.

I also tried using NavigationService instead of Frame as below, with no luck

        if (!UserService.Current.User.IsAuthenticated)
        {
            MessageBox.Show("Navigating away");
            this.NavigationService.Navigate(new Uri("/Views/Login.xaml", UriKind.Relative));
        }

it still does not work. Does anyone know how to make some page accessible only if I have fully valid user object? if they try to access the restricted page without this, I want them to be able to redirected to Login page, how can this be achieved?

I am using Silverlight 3 Beta

Shreedhar

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

萌辣 2024-07-28 22:24:23

我终于找到了解决这个问题的方法。 在 Constructo 中,我连接了 Loaded 事件处理程序,在事件处理程序中,我导航到另一个页面,现在工作正常。

    public Dashboard()
    {
        InitializeComponent();
        this.Loaded += new RoutedEventHandler(Dashboard_Loaded);
    }

    void Dashboard_Loaded(object sender, RoutedEventArgs e)
    {
        if (!UserService.Current.User.IsAuthenticated)
        {
            Frame objContainer = this.Parent as Frame;
            if (objContainer != null)
            {
                objContainer.Navigate(new Uri("/Views/Login.xaml", UriKind.Relative));
            }
        }
    }

这段代码运行得很好!

什里达尔

I finally found a way around this. In the Constructo i Hooked up the Loaded event handler and in the event handler I am navigating to a different page and it works fine now.

    public Dashboard()
    {
        InitializeComponent();
        this.Loaded += new RoutedEventHandler(Dashboard_Loaded);
    }

    void Dashboard_Loaded(object sender, RoutedEventArgs e)
    {
        if (!UserService.Current.User.IsAuthenticated)
        {
            Frame objContainer = this.Parent as Frame;
            if (objContainer != null)
            {
                objContainer.Navigate(new Uri("/Views/Login.xaml", UriKind.Relative));
            }
        }
    }

This piece of code works just fine!

Shreedhar

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文