当前位置: 首页>>代码示例>>C#>>正文


C# OperationContext.ThrowIf方法代码示例

本文整理汇总了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();
       }
 }
开发者ID:yuanfei05,项目名称:vita,代码行数:46,代码来源:LoginModule_LoginService.cs

示例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;
 }
开发者ID:yuanfei05,项目名称:vita,代码行数:7,代码来源:LoginModule.cs

示例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");
 }
开发者ID:yuanfei05,项目名称:vita,代码行数:8,代码来源:LoginModule_Management.cs


注:本文中的OperationContext.ThrowIf方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。