1

Sitecore 8.2r170728, MVC 5, and AspNet Identity

We want to require direct links to pages of our site that require a logged in user to redirect to our login page and then return to the originally requested page.

This is working in my local dev environment but not when I deploy to higher environments like UA. As far as I can tell, the two environments are configured the same.

In my local environment, I see the desired result:

enter image description here

In my UA environment, I see the undesired result:

enter image description here

The request should be redirected to /account-login?ReturnUrl=... instead of /login.aspx?ReturnUrl=...

My ConfigureAuth code:

public void ConfigureAuth(IAppBuilder app)
{
    // Configure the db context, user manager and signin manager to use a single instance per request
    app.CreatePerOwinContext(ApplicationDbContext.Create);
    app.CreatePerOwinContext<ApplicationUserManager>(ApplicationUserManager.Create);
    app.CreatePerOwinContext<ApplicationSignInManager>(ApplicationSignInManager.Create);

    // Enable the application to use a cookie to store information for the signed in user
    // and to use a cookie to temporarily store information about a user logging in with a third party login provider
    // Configure the sign in cookie
    app.UseCookieAuthentication(new CookieAuthenticationOptions
    {
        AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
        LoginPath = new PathString("/account-login"),
        Provider = new CookieAuthenticationProvider
        {
            // Enables the application to validate the security stamp when the user logs in.
            // This is a security feature which is used when you change a password or add an external login to your account.  
            OnValidateIdentity = SecurityStampValidator.OnValidateIdentity<ApplicationUserManager, ApplicationUser>(
                validateInterval: TimeSpan.FromMinutes(30),
                regenerateIdentity: (manager, user) => user.GenerateUserIdentityAsync(manager))
        }
    });
    app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);

    // Enables the application to temporarily store user information when they are verifying the second factor in the two-factor authentication process.
    app.UseTwoFactorSignInCookie(DefaultAuthenticationTypes.TwoFactorCookie, TimeSpan.FromMinutes(5));

    // Enables the application to remember the second login verification factor such as phone or email.
    // Once you check this option, your second step of verification during the login process will be remembered on the device where you logged in from.
    // This is similar to the RememberMe option when you log in.
    app.UseTwoFactorRememberBrowserCookie(DefaultAuthenticationTypes.TwoFactorRememberBrowserCookie);
}

I don't see anything that stands out in my sites config. I'm not sure what else could be causing the differences. Where would /login.aspx be coming from in my UA?

1

This may be caused by the Forms authentication mode defined in web.config.

<authentication mode="Forms">
    <forms name=".ASPXAUTH" cookieless="UseCookies" loginUrl="/Login.aspx" timeout="1440" />
</authentication>

Find <authentication node in your web.config and compare it with your local environment.

Most probably it's set to None in your local like:

<authentication mode="None">
  • Should be set to none. – josedbaez Jul 25 at 20:22
  • Thanks @josedbaez . Yeah, it should be set to none. Answer updated. – Marek Musielak Jul 25 at 20:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.