我是 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/