2017-09-27 30 views
0

似乎的AccountController(ABP 2.3标准模板版本)发送错误信息到客户端浏览器例如当:GetLoginResultAsync发送错误信息到客户端

  1. 用户类型错误的凭证;
  2. 用户名不存在;
  3. 用户市场为“无效”;

    switch (loginResult.Result) 
    { 
        case AbpLoginResultType.Success: 
         return loginResult; 
        default: 
         throw CreateExceptionForFailedLoginAttempt(loginResult.Result, usernameOrEmailAddress, tenancyName); 
    } 
    

例如,CreateExceptionForFailedLoginAttempt回报UserFriendlyException异常,当AbpLoginResultType.UserIsNotActive为真(用户闲置),但客户端收到一个通用的“发生错误 - 错误!没有详细的服务器发送 “消息,而不是‘友好的消息,’

private Exception CreateExceptionForFailedLoginAttempt(AbpLoginResultType result, string usernameOrEmailAddress, string tenancyName) 
{ 
    switch (result) 
    { 
     case AbpLoginResultType.Success: 
      return new ApplicationException("Don't call this method with a success result!"); 

     case AbpLoginResultType.InvalidUserNameOrEmailAddress: 

      // Wrong Username/password 
      return new UserFriendlyException(L("LoginFailed"), L("UnknownUser"));              

     case AbpLoginResultType.InvalidPassword: 
      return new UserFriendlyException(L("LoginFailed"), L("InvalidUserNameOrPassword")); 
     case AbpLoginResultType.InvalidTenancyName: 
      return new UserFriendlyException(L("LoginFailed"), L("ThereIsNoTenantDefinedWithName{0}", tenancyName)); 
     case AbpLoginResultType.TenantIsNotActive: 
      return new UserFriendlyException(L("LoginFailed"), L("TenantIsNotActive", tenancyName)); 
     case AbpLoginResultType.UserIsNotActive: 
      return new UserFriendlyException(L("LoginFailed"), L("UserIsNotActiveAndCanNotLogin", usernameOrEmailAddress)); 
     case AbpLoginResultType.UserEmailIsNotConfirmed: 
      return new UserFriendlyException(L("LoginFailed"), "UserEmailIsNotConfirmedAndCanNotLogin"); 
     case AbpLoginResultType.LockedOut: 
      return new UserFriendlyException(L("LoginFailed"), L("UserLockedOutMessage")); 
     default: //Can not fall to default actually. But other result types can be added in the future and we may forget to handle it 
      Logger.Warn("Unhandled login fail reason: " + result); 
      return new UserFriendlyException(L("LoginFailed")); 
    } 
} 

我看看log.txt文件,发现

WARN 2017-09-27 10:51:55,219 [8] MPA_EF.Web.Controllers.AccountController - 登录失败! Abp.UI.UserFriendlyException:登录失败! at BBWP_ABP_MPA_EF.Web.Controllers.AccountController.d__13.MoveNext()in C:_Ambienti \ vs2015 \ Biosic \ module-zero-template-2.1.1 \ src \ BBWP_ABP_MPA_EF.Web \ Controllers \ AccountController.cs:line 130 - - 从以前位置抛出异常的位置结束堆栈--- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System。 Runtime.CompilerServices.TaskAwaiter 1.GetResult() at BBWP_ABP_MPA_EF.Web.Controllers.AccountController.<Login>d__12.MoveNext() in C:\_Ambienti\vs2015\Biosic\module-zero-template-2.1.1\src\BBWP_ABP_MPA_EF.Web\Controllers\AccountController.cs:line 100 --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Web.Mvc.Async.TaskAsyncActionDescriptor.EndExecute(IAsyncResult asyncResult) at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass37.<BeginInvokeAsynchronousActionMethod>b__36(IAsyncResult asyncResult) at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult 1.CallEndDelegate(IAsyncResult的asyncResult) 在System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResultBase 1.End() at System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethod(IAsyncResult asyncResult) at System.Web.Mvc.Async.AsyncControllerActionInvoker.AsyncInvocationWithFilters.<InvokeActionMethodFilterAsynchronouslyRecursive>b__3d() at System.Web.Mvc.Async.AsyncControllerActionInvoker.AsyncInvocationWithFilters.<>c__DisplayClass46.<InvokeActionMethodFilterAsynchronouslyRecursive>b__3f() at System.Web.Mvc.Async.AsyncControllerActionInvoker.AsyncInvocationWithFilters.<>c__DisplayClass46.<InvokeActionMethodFilterAsynchronouslyRecursive>b__3f() at System.Web.Mvc.Async.AsyncControllerActionInvoker.AsyncInvocationWithFilters.<>c__DisplayClass46.<InvokeActionMethodFilterAsynchronouslyRecursive>b__3f() at System.Web.Mvc.Async.AsyncControllerActionInvoker.AsyncInvocationWithFilters.<>c__DisplayClass46.<InvokeActionMethodFilterAsynchronouslyRecursive>b__3f() at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass33.<BeginInvokeActionMethodWithFilters>b__32(IAsyncResult asyncResult) at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult 1.CallEndDelegate(IAsyncResult的asyncResult) 在System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResultBase`1。结束() at System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethodWithFilters(IAsyncResult asyncResult) at System.Web.Mvc.Async.AsyncControllerActionInvoker。 <> c__DisplayClass21。 <> c__DisplayClass2b.b__1c() at System.Web.Mvc.Async.AsyncControllerActionInvoker。 <> c__DisplayClass21.b__1e(IAsyncResult的asyncResult)

编辑 在登录方法

Standard Login method AccountController.cs

Login method inside my project

+0

嗨亚伦, 没有它里面的AccountController – Saro

+0

GetLoginResultAsync方法内部控制的登录方法调用GetLoginResultAsync 反正租户是该应用程序禁用 – Saro

+0

没有,一切都是“标准” – Saro

回答

0

没有定制查看所提供的日志我看到的处理没有问题,你的码。我能想到的唯一的事情就是您的配置问题web.config

确保<customErrors />标记设置为<customErrors mode="RemoteOnly" /><customErrors mode="On" />

+0

是 由于一些奇怪的原因,我更改了web.config文件中的值,现在可以正常工作。 理解导致显示通用消息的一轮代码会很有趣 – Saro