本文整理汇总了C#中IMansionContext.SetCurrentUserState方法的典型用法代码示例。如果您正苦于以下问题:C# IMansionContext.SetCurrentUserState方法的具体用法?C# IMansionContext.SetCurrentUserState怎么用?C# IMansionContext.SetCurrentUserState使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IMansionContext
的用法示例。
在下文中一共展示了IMansionContext.SetCurrentUserState方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Authenticate
/// <summary>
/// Authenticates the user.
/// </summary>
/// <param name="context">The <see cref="IMansionContext"/>.</param>
/// <param name="authenticationProviderName">The name of the authentication provider.</param>
/// <param name="parameters">The parameters used for authentication.</param>
/// <returns>Returns the <see cref="AuthenticationResult"/>.</returns>
public AuthenticationResult Authenticate(IMansionContext context, string authenticationProviderName, IPropertyBag parameters)
{
// validate arguments
if (context == null)
throw new ArgumentNullException("context");
if (string.IsNullOrEmpty(authenticationProviderName))
throw new ArgumentNullException("authenticationProviderName");
if (parameters == null)
throw new ArgumentNullException("parameters");
// get the authentication provider
var authenicationProvider = ResolveAuthenticationProvider(context, authenticationProviderName);
// invoke template method
var result = DoAuthenticate(context, authenicationProvider, parameters);
// set the user on the context if authentication was succesful
if (result.WasSuccesful)
context.SetCurrentUserState(result.UserState);
// return result
return result;
}
示例2: Logoff
/// <summary>
/// Logs the user of from the current <see cref="IMansionContext"/>.
/// </summary>
/// <param name="context">The <see cref="IMansionContext"/>.</param>
public void Logoff(IMansionContext context)
{
// validate arguments
if (context == null)
throw new ArgumentNullException("context");
// if the user was not authenticated, there is noone to logoff
if (!context.CurrentUserState.IsAuthenticated)
return;
// get the authentication provider name of the user being logged off
var authenticationProviderName = context.CurrentUserState.AuthenticationProviderName;
var authenicationProvider = ResolveAuthenticationProvider(context, authenticationProviderName);
// invoke template method
DoLogoff(context, authenicationProvider);
// set the anonymous user
context.SetCurrentUserState(UserState.AnonymousUser);
}