在mvc中进行身份验证并重定向到silverlight,如何访问经过身份验证的用户

本文关键字:身份验证 访问 何访问 用户 经过 silverlight mvc 重定向 | 更新日期: 2023-09-27 17:57:44

我是silverlight的新手,正在开发一个以mvc为宿主的silverlight应用程序。用户将登录aspx页面/LogOn,并将重定向到silverlight应用程序或其他视图。为了访问silverlight中的登录用户,在mvc中添加了身份验证服务。

app.xaml.cs基于在RIA服务中启用身份验证进行修改

    public App()
    {
        this.Startup += this.Application_Startup;
        this.Exit += this.Application_Exit;
        this.UnhandledException += this.Application_UnhandledException;
        InitializeComponent();
        WebContext webcontext = new WebContext
                                    {
                                        Authentication = new FormsAuthentication()
                                    };
        this.ApplicationLifetimeObjects.Add(webcontext);
        WebContext.Current.Authentication.LoadUser().Completed += 
            (s, e) => MessageBox.Show(WebContext.Current.User.Name);
    }

这种方法不起作用,因为消息框显示为空

在mvc中进行身份验证并重定向到silverlight,如何访问经过身份验证的用户

您可以创建具有以下属性的WCF服务:

[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]

这将允许访问当前登录的用户标识。

    if(HttpContext.Current.User.Identity.IsAuthenticated)
    {
        return HttpContext.Current.User.Identity.Name;
    }
    else
    {
        return null;
    }
相关文章: