我正在构建一个应用程序并将其与活动目录集成。
因此,我将我的应用程序用户身份验证给活动目录用户,之后我将一些用户的数据存储为:user group and user profile
到通用主体和用户身份到通用身份。
我的问题是当我想使用它时,我无法从通用主体获取用户配置文件数据。
有人可以告诉我怎么做吗?
string cookieName = FormsAuthentication.FormsCookieName;
HttpCookie authCookie = Context.Request.Cookies[cookieName];
if (authCookie == null)
{
//There is no authentication cookie.
return;
}
FormsAuthenticationTicket authTicket = null;
try
{
authTicket = FormsAuthentication.Decrypt(authCookie.Value);
}
catch (Exception ex)
{
//Write the exception to the Event Log.
return;
}
if (authTicket == null)
{
//Cookie failed to decrypt.
return;
}
String data = authTicket.UserData.Substring(0, authTicket.UserData.Length -1);
string[] userProfileData = data.Split(new char[] { '|' });
//Create an Identity.
GenericIdentity id =
new GenericIdentity(authTicket.Name, "LdapAuthentication");
//This principal flows throughout the request.
GenericPrincipal principal = new GenericPrincipal(id, userProfileData);
Context.User = principal;
注意:上面的代码在全局 asax 文件中,我想使用我存储在另一个名为default.aspx
.