Geta / geta-notfoundhandler

The popular NotFound handler for ASP.NET Core and Optimizely, enabling better control over your 404 page in addition to allowing redirects for old URLs that no longer works.
Apache License 2.0
20 stars 16 forks source link

NotFoundHandler menu is not available within CMS #85

Closed Deepa-Puranik closed 1 year ago

Deepa-Puranik commented 1 year ago

After adding the necessary packages and configuration in StartUp file, not able to access the NotFoundHandler menu in CMS. CMS version installed is EPiServer.CMS(12.17.0) and packages installed are Geta.NotFoundHandler, Geta.NotFoundHandler.Admin and Geta.NotfoundHandler.Optimizely version 5.0.6. Added necessary configuration in appSettings.json and the custom error page is also not working. Please help if there is any missing configuration to make it work.

marisks commented 1 year ago

How does your configuration look in Startup?

Deepa-Puranik commented 1 year ago

StartUp file

var connectionString = this.Configuration.GetConnectionString("EPiServerDB");// Retrieve connection string here services.AddNotFoundHandler(o => { o.UseSqlServer(connectionString); o.BufferSize = 30; o.ThreshHold = 5; o.HandlerMode = FileNotFoundMode.On; o.IgnoredResourceExtensions = new[] { "jpg", "gif", "png", "css", "js", "ico", "swf", "woff" }; o.Logging = LoggerMode.On; o.LogWithHostname = false; }); services.AddOptimizelyNotFoundHandler(o => { o.AutomaticRedirectsEnabled = true; });

marisks commented 1 year ago

These should be the first ones in the Configure method: app.UseNotFoundHandler(); app.UseOptimizelyNotFoundHandler();

Deepa-Puranik commented 1 year ago

Updated like this in Alloy template : public void ConfigureServices(IServiceCollection services) { if (_webHostingEnvironment.IsDevelopment()) { AppDomain.CurrentDomain.SetData("DataDirectory", Path.Combine(_webHostingEnvironment.ContentRootPath, "App_Data"));

            services.Configure<SchedulerOptions>(options => options.Enabled = false);
        }
        var connectionString = "Data Source=(LocalDB)\\MSSQLLocalDB;AttachDbFilename=" +

"|DataDirectory|\TestOptimizely.mdf; " + "Integrated Security=True;MultipleActiveResultSets=True";// Retrieve connection string here services.AddNotFoundHandler(o => { o.UseSqlServer(connectionString); o.BufferSize = 30; o.ThreshHold = 5; o.HandlerMode = FileNotFoundMode.On; o.IgnoredResourceExtensions = new[] { "jpg", "gif", "png", "css", "js", "ico", "swf", "woff" }; o.Logging = LoggerMode.On; o.LogWithHostname = false; }); services.AddOptimizelyNotFoundHandler(o => { o.AutomaticRedirectsEnabled = true; }); services .AddCmsAspNetIdentity() .AddCms() .AddAlloy() .AddAdminUserRegistration() .AddEmbeddedLocalization();

        // Required by Wangkanai.Detection
        services.AddDetection();

        services.AddSession(options =>
        {
            options.IdleTimeout = TimeSpan.FromSeconds(10);
            options.Cookie.HttpOnly = true;
            options.Cookie.IsEssential = true;
        });
        services.AddForteEpiResponsivePicture();
    }

    public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
    {
        if (env.IsDevelopment())
        {
            app.UseDeveloperExceptionPage();
        }
        app.UseNotFoundHandler();
        app.UseOptimizelyNotFoundHandler();
        // Required by Wangkanai.Detection
        app.UseDetection();
        app.UseSession();

        app.UseStaticFiles();
        app.UseRouting();
        app.UseAuthentication();
        app.UseAuthorization();

        app.UseEndpoints(endpoints =>
        {
            endpoints.MapContent();
            endpoints.MapRazorPages();
        });
        app.UseForteEpiResponsivePicture();
    }

Still not able to see NotFoundHandler menu in CMS.

marisks commented 1 year ago

Maybe it requires AddRazorPages in ConfigureServices

Deepa-Puranik commented 1 year ago

Added this line services.AddRazorPages(); in ConfigureServices. Still not able to see the handler.

Deepa-Puranik commented 1 year ago

Thank you, for your quick response on this. The issue got resolved.