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

标签 c# asp.net asp.net-mvc silverlight forms-authentication

我是 silverlight 的新手,正在开发一个托管在 mvc 中的 silverlight 应用程序。用户将登录到 aspx 页面 /LogOn 并将被重定向到 silverlight 应用程序或另一个 View 。为了在 silverlight 中访问登录的用户,在 mvc 中添加了身份验证服务。

app.xaml.cs 根据Enable authentication in RIA services修改

    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);
    }

此方法无效,因为消息框显示为空

最佳答案

您可以使用该属性创建 WCF 服务:

[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]

这将允许访问当前登录的用户身份。

    if(HttpContext.Current.User.Identity.IsAuthenticated)
    {
        return HttpContext.Current.User.Identity.Name;
    }

    else
    {
        return null;
    }

关于c# - 在 mvc 中进行身份验证并重定向到 silverlight,如何访问经过身份验证的用户?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6151220/

相关文章:

asp.net - 当 AppFabric 崩溃时, session 状态如何仍然可用?

ios - ASP.NET 检索 iOS 应用程序到期日期

c# - 条件运算符在 MVC Razor 中的某个地方运行不正常?

c# - 无法使用 Unity 解析的类型 [MVC 5]

c# - 如何从 xaml 中引用 .resx 文件中的图标?

c# - 使用Icomparer的CustomSort字符串

javascript - Facebook Connect - 单点登录导致无限循环 :(

jquery - MVC jQuery 日期选择器返回 dd/MM/yyyyyyyy

c# - 将 DataTable 保存到数据库表中

c# - 如何将列表从 View 发送到 Controller MVC