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
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;
}
精彩评论