Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Aaron 29 posts 240 karma points c-trib
    Oct 01, 2021 @ 09:06
    Aaron
    0

    How to change the access denied route?

    How can I change the access denied route using UmbracoMemberAuthorize.

    Currently it is going to /Account/AccessDenied?redirecturl=

    I would like it to go /Clients/Login?redirecturl=

    Thanks!

  • Bjarke Berg 29 posts 262 karma points hq
    Oct 01, 2021 @ 09:28
    Bjarke Berg
    101

    You can implement a custom configure options for the member options

    public class ConfigureCustomMemberCookieOptions : IConfigureNamedOptions<CookieAuthenticationOptions>
    {
        public void Configure(string name, CookieAuthenticationOptions options)
        {
            if (name == IdentityConstants.ApplicationScheme || name == IdentityConstants.ExternalScheme)
            {
                Configure(options);
            }
        }
    
        public void Configure(CookieAuthenticationOptions options)
        {
            options.AccessDeniedPath = "/Clients/Login?redirecturl=";
    
        }
    }
    

    And then register it in the container, e.g. like this in startup.cs

        public void ConfigureServices(IServiceCollection services)
        {
            services.AddUmbraco(_env, _config)
                .AddBackOffice()
                .AddWebsite()
                .AddComposers()
                .Build();
    
            services.ConfigureOptions<ConfigureCustomMemberCookieOptions>();
    
        }
    
  • Aaron 29 posts 240 karma points c-trib
    Oct 01, 2021 @ 09:29
    Aaron
    0

    Brilliant!

    Thanks Bjarke!

Please Sign in or register to post replies

Write your reply to:

Draft