Roz*_*uur 5 c# asp.net silverlight asp.net-mvc forms-authentication
我是silverlight的新手,正在研究mvc中托管的silverlight应用程序.用户将登录aspx页面/ LogOn,并将被重定向到silverlight应用程序或其他视图.要在silverlight中访问已登录用户,请在mvc中添加身份验证服务.
app.xaml.cs基于RIA服务中的启用身份验证进行了修改
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);
}
Run Code Online (Sandbox Code Playgroud)
这种方法不起作用,因为消息框显示为空
您可以使用该属性创建 WCF 服务:
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
Run Code Online (Sandbox Code Playgroud)
这将允许访问当前登录的用户身份。
if(HttpContext.Current.User.Identity.IsAuthenticated)
{
return HttpContext.Current.User.Identity.Name;
}
else
{
return null;
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
645 次 |
最近记录: |