【问题标题】:authenticate in mvc and redirect to silverlight, how to access authenticated user?在 mvc 中进行身份验证并重定向到 silverlight,如何访问经过身份验证的用户?
【发布时间】:2011-05-27 10:51:36
【问题描述】:

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

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

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

【问题讨论】:

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


    【解决方案1】:

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

    [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
    

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

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

    【讨论】:

      猜你喜欢
      • 2015-04-20
      • 1970-01-01
      • 2019-04-25
      • 2016-01-15
      • 2020-02-22
      • 1970-01-01
      • 2016-01-17
      • 1970-01-01
      • 2015-06-26
      相关资源
      最近更新 更多