Silverlight 导航和身份验证服务
我正在使用导航应用程序模板创建一个银光应用程序。 它供内部使用,因此使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我终于找到了解决这个问题的方法。 在 Constructo 中,我连接了 Loaded 事件处理程序,在事件处理程序中,我导航到另一个页面,现在工作正常。
这段代码运行得很好!
什里达尔
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.
This piece of code works just fine!
Shreedhar