Base solution for your next web application
Open Closed

caught exceptions #214


User avatar
0
cicciottino created

i'm trying to install ModuleZero from scrath following the link: <a class="postlink" href="http://aspnetboilerplate.com/Pages/Documents/Zero/installation#DocInstallManual">http://aspnetboilerplate.com/Pages/Docu ... tallManual</a>

in the Login(POST)method of AccountController i got an error

[HttpPost]
        public async Task<JsonResult> Login(LoginViewModel loginModel, string returnUrl = "")
        {
            if (!ModelState.IsValid)
            {
                throw new UserFriendlyException("Your form is invalid!");
            }
								                                        //=================================
            var loginResult = await _userManager.LoginAsync(    //<--HERE IS WHERE I GOT THE ERROR
                loginModel.UsernameOrEmailAddress,              //=================================
                loginModel.Password,
                loginModel.TenancyName
                );

            switch (loginResult.Result)
            {
                case AbpLoginResultType.Success:
                    break;
                case AbpLoginResultType.InvalidUserNameOrEmailAddress:
                case AbpLoginResultType.InvalidPassword:
                    throw new UserFriendlyException("Invalid user name or password!");
                case AbpLoginResultType.InvalidTenancyName:
                    throw new UserFriendlyException("No tenant with name: " + loginModel.TenancyName);
                case AbpLoginResultType.TenantIsNotActive:
                    throw new UserFriendlyException("Tenant is not active: " + loginModel.TenancyName);
                case AbpLoginResultType.UserIsNotActive:
                    throw new UserFriendlyException("User is not active: " + loginModel.UsernameOrEmailAddress);
                case AbpLoginResultType.UserEmailIsNotConfirmed:
                    throw new UserFriendlyException("Your email address is not confirmed!");
                default: //Can not fall to default for now. But other result types can be added in the future and we may forget to handle it
                    throw new UserFriendlyException("Unknown problem with login: " + loginResult.Result);
            }

            AuthenticationManager.SignOut(DefaultAuthenticationTypes.ExternalCookie);
            AuthenticationManager.SignIn(new AuthenticationProperties { IsPersistent = loginModel.RememberMe }, loginResult.Identity);

            if (string.IsNullOrWhiteSpace(returnUrl))
            {
                returnUrl = Request.ApplicationPath;
            }

            return Json(new MvcAjaxResponse { TargetUrl = returnUrl });
        }

the error is only visible with the browser tool(F12-->network)

Multiple object sets per type are not supported. The object sets 'Roles' and 'Roles' can both contain instances of type 'ModuleZeroFromScratch.Authorization.Roles.Role'

so (as you suggest me in the past) i placed the class

public class MyExceptionHandler : IEventHandler<AbpHandledExceptionData>, ITransientDependency
    {
        public void HandleEvent(AbpHandledExceptionData eventData)
        {
            //TODO: Check eventData.Exception!
        }
    }

into the web project but nothing. Again, i put this class in the "Core" module (where the source of error is, "UserManager") but nothing.

the questions are:

  1. putting this class in the Web project(the outermost) does it catch exceptions occurred in every module? or only in the module where such a class is present? If it is the first why this does not happen?

  2. do you have an idea from the message what is the problem or at least what i should check?


3 Answer(s)
  • User Avatar
    0
    hikalkan created
    Support Team
    1. Putting a handler in the solution is enough. But in this case, maybe ABP did not handled the error. You can change CustomErrors from "On" to "RemoteOnly". This may help to get detailed errors.

    2. Check your solution if you have more than one Role class (in different namespaces). It should be single. This is EntityFramework's error, not ABP's. Also, you may have DbSet<Role> in your dbcontext. Remove it since AbpZeroDbContext has already same dbset.

  • User Avatar
    0
    cicciottino created

    you're right i've duplicated the DbSet's

    so now i got this error on the Account/Login

    There should be a 'Default' tenant if multi-tenancy is disabled!
    

    where i should provide this default value? in the model? in the seed method? directly into the db?

  • User Avatar
    0
    hikalkan created
    Support Team

    In seed (like <a class="postlink" href="http://www.aspnetboilerplate.com/Pages/Documents/Zero/Installation#DocInitialData">http://www.aspnetboilerplate.com/Pages/ ... nitialData</a>)