本文整理汇总了C#中OperationContext.ThrowIf方法的典型用法代码示例。如果您正苦于以下问题:C# OperationContext.ThrowIf方法的具体用法?C# OperationContext.ThrowIf怎么用?C# OperationContext.ThrowIf使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OperationContext
的用法示例。
在下文中一共展示了OperationContext.ThrowIf方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Login
public LoginResult Login(OperationContext context, string userName, string password, Guid? tenantId = null,
string deviceToken = null)
{
context.ThrowIf(password.Length > 100, ClientFaultCodes.InvalidValue, "password", "Password too long, max size: 100.");
var webCtx = context.WebContext;
userName = CheckUserName(context, userName);
var session = context.OpenSystemSession();
var login = FindLogin(session, userName, password, tenantId);
if(login == null) {
if(webCtx != null)
webCtx.Flags |= WebCallFlags.AttackRedFlag;
OnLoginEvent(context, LoginEventType.LoginFailed, null, userName: userName);
LogIncident(context, LoginIncidentType, LoginEventType.LoginFailed.ToString(), "User: " + userName, null, userName);
return new LoginResult() { Status = LoginAttemptStatus.Failed };
}
var device = login.GetDevice(deviceToken);
try {
var status = CheckCanLoginImpl(login, device);
//Check non-success statuses
switch(status) {
case LoginAttemptStatus.Success:
PostLoginActions actions = GetPostLoginActions(login);
context.User = login.CreateUserInfo();
if(_sessionService != null)
AttachUserSession(context, login, device);
App.UserLoggedIn(context);
var lastLogin = login.LastLoggedInOn; //save prev value
UpdateLastLoggedInOn(login);
OnLoginEvent(context, LoginEventType.Login, login, userName: userName);
var sessionToken = context.UserSession == null ? null : context.UserSession.Token;
return new LoginResult() { Status = status, Login = login, Actions = actions, User = context.User, SessionToken = sessionToken, LastLoggedInOn = lastLogin };
case LoginAttemptStatus.PendingMultifactor:
OnLoginEvent(context, LoginEventType.LoginPendingMultiFactor, login, userName: userName);
return new LoginResult() { Status = status, Login = login };
case LoginAttemptStatus.AccountInactive:
OnLoginEvent(context, LoginEventType.LoginFailed, login, "Login failed due to inactive status", userName: userName);
return new LoginResult() { Status = status, Login = login };
case LoginAttemptStatus.Failed:
default:
OnLoginEvent(context, LoginEventType.LoginFailed, login, userName: userName);
return new LoginResult() { Status = status };
}
} finally {
session.SaveChanges();
}
}
示例2: CheckUserName
private string CheckUserName(OperationContext context, string userName)
{
context.ThrowIfEmpty(userName, ClientFaultCodes.ValueMissing, "UserName", userName, "User name may not be empty");
userName = userName.Trim().ToLowerInvariant();
context.ThrowIf(userName.Length < 3, LoginFaultCodes.UserNameTooShort, "UserName", userName, "User name is too short");
return userName;
}
示例3: CheckPasswordStrength
private void CheckPasswordStrength(OperationContext context, string password)
{
context.ThrowIfEmpty(password, ClientFaultCodes.InvalidValue, "password", "Password may not be empty.");
context.ThrowIf(password.Length > 100, ClientFaultCodes.InvalidValue, "password", "Password too long, max size: 100.");
var pwdStrength = EvaluatePasswordStrength(password);
var pwdOk = pwdStrength >= _settings.RequiredPasswordStrength;
context.ThrowIf(!pwdOk, LoginFaultCodes.WeakPassword, "Password", "Password does not meet strength criteria");
}