Base solution for your next web application
Open Closed

Problem with redirecting after login #130


User avatar
0
hans abelshausen created

Hi, do you have an answer, why Redirect is not working as expected:

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

in your example, everything works fine, in my own project, if I log in, the following URL is shown instead of the correct one: this is the Login URL: <a class="postlink" href="http://localhost:6234/Account/Login?ReturnUrl=%2F">http://localhost:6234/Account/Login?ReturnUrl=%2F</a> and after correct log in: <a class="postlink" href="http://localhost:6234/Account/Login?ReturnUrl=%2F">http://localhost:6234/Account/Login?ReturnUrl=%2F</a> exactly the same... if I link to Google it works...


16 Answer(s)
  • User Avatar
    0
    hikalkan created
    Support Team

    It normally should redirect. Are you using abp.ajax method to call the MVC action?

  • User Avatar
    0
    hans abelshausen created

    Yes, I have copied the code of your sample Project and the login page is shown, then I took username admin and your Password. In Accountcontroller loginResult is success but this code is never reached:

    [AbpMvcAuthorize]
        public class HomeController : MyProjectControllerBase
        {
            public ActionResult Index()
            {
                return View("~/App/Main/views/layout/layout.cshtml"); 
            }
        }
    
  • User Avatar
    0
    hikalkan created
    Support Team

    Can you give some additional info. Which version of ABP and module-zero are you using and is there any exception log in Logs folder of web site?

  • User Avatar
    0
    hans abelshausen created

    It seems user is not logged in, but I don't know what is different in my Project... Here is the log file:

    DEBUG 2015-06-08 11:16:56,063 [1 ] Abp.Localization.LocalizationManager - Initializing 4 localization sources. DEBUG 2015-06-08 11:16:56,067 [1 ] Abp.Localization.LocalizationManager - Initialized localization source: Abp DEBUG 2015-06-08 11:16:56,067 [1 ] Abp.Localization.LocalizationManager - Initialized localization source: AbpZero DEBUG 2015-06-08 11:16:56,067 [1 ] Abp.Localization.LocalizationManager - Initialized localization source: AbpWeb DEBUG 2015-06-08 11:16:57,992 [1 ] Abp.Localization.LocalizationManager - Initialized localization source: Test WARN 2015-06-08 11:16:58,315 [10 ] Default - Abp.Authorization.AbpAuthorizationException: No user logged in! bei Abp.Authorization.AuthorizeAttributeHelper.<AuthorizeAsync>d__0.MoveNext() --- Ende der Stapelüberwachung vom vorhergehenden Ort, an dem die Ausnahme ausgelöst wurde --- bei System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) bei System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) bei System.Runtime.CompilerServices.TaskAwaiter.GetResult() bei Nito.AsyncEx.Synchronous.TaskExtensions.WaitAndUnwrapException(Task task) bei Nito.AsyncEx.AsyncContext.<>c__DisplayClass3.<Run>b__1(Task t) bei System.Threading.Tasks.ContinuationTaskFromTask.InnerInvoke() bei System.Threading.Tasks.Task.Execute() --- Ende der Stapelüberwachung vom vorhergehenden Ort, an dem die Ausnahme ausgelöst wurde --- bei System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) bei System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) bei System.Runtime.CompilerServices.TaskAwaiter.GetResult() bei Nito.AsyncEx.Synchronous.TaskExtensions.WaitAndUnwrapException(Task task) bei Nito.AsyncEx.AsyncContext.Run(Func1 action) bei Abp.Threading.AsyncHelper.RunSync(Func1 action) bei Abp.Authorization.AuthorizeAttributeHelper.Authorize(IEnumerable1 authorizeAttributes) bei Abp.Authorization.AuthorizeAttributeHelper.Authorize(IAbpAuthorizeAttribute authorizeAttribute) bei Abp.Web.Mvc.Authorization.AbpMvcAuthorizeAttribute.AuthorizeCore(HttpContextBase httpContext) Abp.Authorization.AbpAuthorizationException: No user logged in! bei Abp.Authorization.AuthorizeAttributeHelper.<AuthorizeAsync>d__0.MoveNext() --- Ende der Stapelüberwachung vom vorhergehenden Ort, an dem die Ausnahme ausgelöst wurde --- bei System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) bei System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) bei System.Runtime.CompilerServices.TaskAwaiter.GetResult() bei Nito.AsyncEx.Synchronous.TaskExtensions.WaitAndUnwrapException(Task task) bei Nito.AsyncEx.AsyncContext.<>c__DisplayClass3.<Run>b__1(Task t) bei System.Threading.Tasks.ContinuationTaskFromTask.InnerInvoke() bei System.Threading.Tasks.Task.Execute() --- Ende der Stapelüberwachung vom vorhergehenden Ort, an dem die Ausnahme ausgelöst wurde --- bei System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) bei System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) bei System.Runtime.CompilerServices.TaskAwaiter.GetResult() bei Nito.AsyncEx.Synchronous.TaskExtensions.WaitAndUnwrapException(Task task) bei Nito.AsyncEx.AsyncContext.Run(Func1 action) bei Abp.Threading.AsyncHelper.RunSync(Func1 action) bei Abp.Authorization.AuthorizeAttributeHelper.Authorize(IEnumerable1 authorizeAttributes) bei Abp.Authorization.AuthorizeAttributeHelper.Authorize(IAbpAuthorizeAttribute authorizeAttribute) bei Abp.Web.Mvc.Authorization.AbpMvcAuthorizeAttribute.AuthorizeCore(HttpContextBase httpContext) WARN 2015-06-08 11:17:15,594 [12 ] Default - Abp.Authorization.AbpAuthorizationException: No user logged in! bei Abp.Authorization.AuthorizeAttributeHelper.<AuthorizeAsync>d__0.MoveNext() --- Ende der Stapelüberwachung vom vorhergehenden Ort, an dem die Ausnahme ausgelöst wurde --- bei System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) bei System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) bei System.Runtime.CompilerServices.TaskAwaiter.GetResult() bei Nito.AsyncEx.Synchronous.TaskExtensions.WaitAndUnwrapException(Task task) bei Nito.AsyncEx.AsyncContext.<>c__DisplayClass3.<Run>b__1(Task t) bei System.Threading.Tasks.ContinuationTaskFromTask.InnerInvoke() bei System.Threading.Tasks.Task.Execute() --- Ende der Stapelüberwachung vom vorhergehenden Ort, an dem die Ausnahme ausgelöst wurde --- bei System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) bei System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) bei System.Runtime.CompilerServices.TaskAwaiter.GetResult() bei Nito.AsyncEx.Synchronous.TaskExtensions.WaitAndUnwrapException(Task task) bei Nito.AsyncEx.AsyncContext.Run(Func1 action) bei Abp.Threading.AsyncHelper.RunSync(Func1 action) bei Abp.Authorization.AuthorizeAttributeHelper.Authorize(IEnumerable1 authorizeAttributes) bei Abp.Authorization.AuthorizeAttributeHelper.Authorize(IAbpAuthorizeAttribute authorizeAttribute) bei Abp.Web.Mvc.Authorization.AbpMvcAuthorizeAttribute.AuthorizeCore(HttpContextBase httpContext) Abp.Authorization.AbpAuthorizationException: No user logged in! bei Abp.Authorization.AuthorizeAttributeHelper.<AuthorizeAsync>d__0.MoveNext() --- Ende der Stapelüberwachung vom vorhergehenden Ort, an dem die Ausnahme ausgelöst wurde --- bei System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) bei System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) bei System.Runtime.CompilerServices.TaskAwaiter.GetResult() bei Nito.AsyncEx.Synchronous.TaskExtensions.WaitAndUnwrapException(Task task) bei Nito.AsyncEx.AsyncContext.<>c__DisplayClass3.<Run>b__1(Task t) bei System.Threading.Tasks.ContinuationTaskFromTask.InnerInvoke() bei System.Threading.Tasks.Task.Execute() --- Ende der Stapelüberwachung vom vorhergehenden Ort, an dem die Ausnahme ausgelöst wurde --- bei System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) bei System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) bei System.Runtime.CompilerServices.TaskAwaiter.GetResult() bei Nito.AsyncEx.Synchronous.TaskExtensions.WaitAndUnwrapException(Task task) bei Nito.AsyncEx.AsyncContext.Run(Func1 action) bei Abp.Threading.AsyncHelper.RunSync(Func1 action) bei Abp.Authorization.AuthorizeAttributeHelper.Authorize(IEnumerable1 authorizeAttributes) bei Abp.Authorization.AuthorizeAttributeHelper.Authorize(IAbpAuthorizeAttribute authorizeAttribute) bei Abp.Web.Mvc.Authorization.AbpMvcAuthorizeAttribute.AuthorizeCore(HttpContextBase httpContext)

    I'm using Abp 0.6.2.0 Abp Zero 0.6.0.0

  • User Avatar
    0
    hikalkan created
    Support Team

    Hmm, it seems that your code can not login. Maybe we can help better if you can share your sign in code. Is it similar to <a class="postlink" href="https://github.com/aspnetboilerplate/module-zero/blob/master/sample/ModuleZeroSampleProject.Web/Controllers/AccountController.cs#L44">https://github.com/aspnetboilerplate/mo ... ler.cs#L44</a>

  • User Avatar
    0
    hans abelshausen created

    Yes, I have copied your code, here it is: (in my loginresult.User there is an error: internal error in method "Abp.Authorization.Users.AbpUserManager'3#AbpLoginResult[TTenant, TRole, TUser].get_user()")

    using System.Threading.Tasks;
    using System.Web;
    using System.Web.Mvc;
    using Abp.Authorization.Users;
    using Abp.UI;
    using Abp.Web.Mvc.Models;
    using Microsoft.AspNet.Identity;
    using Microsoft.Owin.Security;
    using Test.Security.Users;
    using Test.Web.Models.Account;
    
    
    namespace Test.Web.Controllers
    {
        public class AccountController : TestControllerBase
        {
            private readonly UserManager _userManager;
    
            private IAuthenticationManager AuthenticationManager
            {
                get
                {
                    return HttpContext.GetOwinContext().Authentication;
                }
            }
    
            public AccountController(UserManager userManager)
            {
                _userManager = userManager;
            }
    
            public ActionResult Login(string returnUrl = "")
            {
                if (string.IsNullOrWhiteSpace(returnUrl))
                {
                    returnUrl = Request.ApplicationPath;
                }
    
                ViewBag.ReturnUrl = returnUrl;
    
                return View();
            }
    
            [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(
                    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
                });
                //return Json(new MvcAjaxResponse 
                //{ 
                //    TargetUrl = returnUrl
                //    //TargetUrl = "/#/"
                //});
            }
    
            public ActionResult Logout()
            {
                AuthenticationManager.SignOut();
                return RedirectToAction("Login");
            }
        }
    }
    
  • User Avatar
    0
    hans abelshausen created

    I have updated to newest version of Abp.Zero and if I check the loginAsync function, there is a difference between my solution and yours. the castle.proxies.usermanagerproxy base AbpSession is Abp.TestBase.Runtime.Session.TestAbpSession in your code it is Abp.Runtime.Session.AbpSession Is this perhaps the problem? Where can I change it?

  • User Avatar
    0
    hikalkan created
    Support Team

    Yes, this is the problem. Abp.TestBase.Runtime.Session.TestAbpSession is the TEST class defined in Abp.TestBase nuget package. You probably somehow added this test package to your production code. Remove this package from your projects and add Abp.Zero package.

  • User Avatar
    0
    hans abelshausen created

    I can't find the test package. I have added the Abp.Zero version 0.6.3.4 Strange...

  • User Avatar
    0
    hikalkan created
    Support Team

    So, is it working now?

  • User Avatar
    0
    hans abelshausen created

    No, I haven't a test package included. Only Abp.Zero version 6.0.3.4 but Abp.TestBase.Runtime.Session.TestAbpSession as Session. Is the TestAbpSession included in the abp.zero package?

  • User Avatar
    0
    hikalkan created
    Support Team

    No, there is no TestAbpSession class in module-zero project. But, adding Abp.Zero package is essential for module-zero (naturally). If you don't add, NullAbpSession is used and you can not login.

  • User Avatar
    0
    hans abelshausen created

    I only installed Abp.Zero and Abp.Zero.EntityFramework, but in accountcontroller _userManager.AbpSession is Abp.TestBase.Runtime.Session.TestAbpSession What I'm doing wrong?

    Here is the wrong Session:

    public UserStore(
                IRepository<User, long> userRepository,
                IRepository<UserLogin, long> userLoginRepository,
                IRepository<UserRole, long> userRoleRepository,
                IRepository<Role> roleRepository,
                IRepository<UserPermissionSetting, long> userPermissionSettingRepository,
                IAbpSession session,
                IUnitOfWorkManager unitOfWorkManager)
                : base(
                    userRepository,
                    userLoginRepository,
                    userRoleRepository,
                    roleRepository,
                    userPermissionSettingRepository,
                    session,
                    unitOfWorkManager)
            {
            }
    
  • User Avatar
    0
    hikalkan created
    Support Team

    It's defined here:

    <a class="postlink" href="https://github.com/aspnetboilerplate/aspnetboilerplate/blob/master/src/TestBase/Abp.TestBase/TestBase/Runtime/Session/TestAbpSession.cs">https://github.com/aspnetboilerplate/as ... Session.cs</a>

    And there is no TestAbpSession other from this one. I could not understand how you are using this. If you really want, zip your solution and send me, I check it when I have time.

  • User Avatar
    0
    hans abelshausen created

    Hi, I have downloaded a brand new project from your site and added my classes. Now Login works perfectly, abp.session is now the right one and not the testbase.session. But I did not found my error. I uninstalled every abp project and reinstalled abp. But still error is shown. So I decided to make a new project! Thanks a lot.

  • User Avatar
    0
    hikalkan created
    Support Team

    I hadn't time to check your codes, sorry. There should be a reference problem but it's a little hard to find. A Second eye could be good to find it.