Active Query Builder support area

How to fix the 404 Not Found error during the request to Active Query Builder handlers?

Last modified:


Active Query Builder automatically registers the route to the System.Web.Routing.RouteTable with the following template:

ActiveQueryBuilder/Handler/{action}/{*params}

We found several possible reasons for the 404 error during the request to AQB handlers.

  1. Working in a client-side rendering mode in a Virtual Directory with IIS.
  2. Running an MVC or WebForms project in a Virtual Directory with IIS.
  3. In some configurations, the automatically added route is removed or redefined due to other customizations.

 

1. Working in a client-side rendering mode in a Virtual Directory.

You can fix this issue by explicitly indicating the virtual directory on which the route will reside on both the client and server-side.

- Use the AQB.Web.virtualDirectory or the AQB.Web.useRelativePaths JavaScript property.

- follow the step below to set up a virtual directory on the server-side via BaseHanlder.

 

2. Running an MVC or WebForms project with a server-side rendering like Razor or ASPX in a Virtual Directory.

You can fix this issue by explicitly indicating the virtual directory on which the route will reside.

You should define the virtual directory in the Application_Start method using the ActiveQueryBuilder.Web.Server.Handlers.BaseHandler.VirtualDirectory static property or you can set the BaseHandler.UseRelativePaths static property to instruct to add "./" to all paths to resources and the AQB handler.

Alternatively (if the abovementioned properties don't help), you can define a rewrite rule to forward calls to the Active Query Builder handlers inside the virtual directory using the URL Rewrite module for IIS for that.

You can add it via the IIS manager UI or manually by adding directives to the 'web.config' file.
Refer to the guides for more details: Creating Rewrite Rules for the URL Rewrite Module.

 

3. In some configurations, the automatically added route is removed or redefined due to other customizations.

If the method above doesn't work, the problem can be fixed by adding the BaseHandler.Register() method at the end of your route configuration routine.

In complex projects, the routing table can be redefined at later stages or an alternative way of routing can be implemented (which is the case for the NancyFx framework). So we recommend exploring the System.Web.Routing.Routes table to get some clues.

If the route used by Active Query Builder by default is not suitable/accessible in your project, you can redefine it as follows:

  • Call the BaseHandler.DisableRegistration() method in the Application_Start routine to deny registering the default route.
  • Set the QueryBuilderControl.HandlersPath to a custom route. In Razor MVC, you can do this as follows:
  var controls = Html.QueryBuilder(Model, s => s.HandlersPath = "Home/Sync");
  • Add the corresponding handler to your controller:

in .NET Framework project:

  public void Sync()
  {
    var factory = new AspNetHandlerFactory();
    var h = factory.CreateHandler(Request);
    h.ProcessRequest();
  }

in .NET Core project:

private readonly IHostingEnvironment _env;
private readonly IQueryBuilderService _aqbs;
private readonly IConfiguration _config;
private readonly IServiceProvider _serviceProvider;
private readonly InMemoryCacheBase _cache;
private readonly IHttpContext _context;

// Use IQueryBuilderService to get access to the server-side instances of Active Query Builder objects. 
// See the registration of this service in the Startup.cs.
public SimpleOfflineDemoController(IQueryBuilderService aqbs, IHostingEnvironment env, IConfiguration config, 
  IServiceProvider serviceProvider, InMemoryCacheBase cache, IHttpContext context)
{
  _aqbs = aqbs;
  _env = env;
  _config = config;
  _serviceProvider = serviceProvider;
  _cache = cache;
  _context = context;
}

public void Sync()
{
  var qbStore = new QueryBuilderStoreInternal(_serviceProvider);
  var qtStore = new QueryTransformerStoreInternal(_serviceProvider);
  var factory = new AspNetCoreHandlerFactory();
  var handler = factory.CreateHandler(HttpContext.Request, _context, qbStore, qtStore, _cache);
  handler.ProcessRequest();
}

Is this article helpful for you?