Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

authenticate in mvc and redirect to silverlight, how to access authenticated user?

I am new to silverlight and working on a silverlight application hosted in mvc. User will login in aspx page /LogOn and will be redirected to either silverlight application or another view. To access logged user in silverlight Authentication service is added in mvc.

app.xaml.cs modified based on 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);
    }

This is approach is not working as Message box is shown as empty

like image 266
Rozuur Avatar asked Nov 13 '22 22:11

Rozuur


1 Answers

You can create a WCF service with that attribute:

[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]

This will enable access to currently loged in User Identity.

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

    else
    {
        return null;
    }
like image 68
Dominic St-Pierre Avatar answered Dec 06 '22 03:12

Dominic St-Pierre