Ext.NET DirectMethod calls are failing when my site runs through CloudFlare

63 Views Asked by At

We have a site which uses Ext.NET for its interface

Part of this interface uses Ext.NET DirectMethods to trigger c# code from a JavaScript call. For example...

c# code...

[DirectMethod]
public static void ExampleDirectMethod(string variablePassed)
{
}

js code...

var runTest = function() {
    Ext.net.DirectMethods.ExampleDirectMethod('testing', {
        success: function (result) {
            console.log((new Date()) + ' - ExampleDirectMethod - result = success');
        },
        failure: function (result) {
            console.log((new Date()) + ' - ExampleDirectMethod - result = ' + JSON.stringify(result));
        }
    });
}

This code worked fine until I set my site to run through CloudFlare

When the site is running through cloudflare, I can see the ajax calls which are triggered by my runTest() function, but instead of the result being a json string, the result is the html of the page that I am running the page from

Normal AJAX calls work fine, it's just these Ext.net.DirectMethod ones which are failing

I can't find any trace on the internet of anyone else having a similar problem


Update: I was able to get static DirectMethods working using the following code, but non static ones are still failing

protected override void OnPreInit(EventArgs e)
{
    if (Request.QueryString["_dc"] != null)
    {
        DirectMethodHandler handler = new DirectMethodHandler();
        handler.ProcessRequest(HttpContext.Current);
    }
}

Update 2: It looks like the problem is only happening with Ext.NET version 1.7 , we have tried upgrading to a newer version (2.5) and the direct methods worked through CloudFlare


Final Update We found the root cause of the problem. The issue is that in Ext.NET 1.7, the ext code looks for an x-ext.net header value in the requests to know whether to process the request as a DirectMethod. Cloudflare strips out all request headers with dots in them, so this is the cause of the DirectMethods not working

Cloudflare will also not allow you to set up a rule to re-add this header value back into the request

The fix is to update your c# code so that if the ?_dc= query string value exists, that you insert the x-ext.net header value back into the request before it can be processed. The values can be either delta=true or delta=true,staticmethod=true for static DirectMethods

You can detect whether a DirectMethod request is for a static one by the presence of a Request.Form["_methodName_"] value

1

There are 1 best solutions below

0
Sachin Ibrahimpur On

https://github.com/extnet/Ext.NET

Ext.NET reached it's end-of-life on December 15, 2023 and is no longer being maintained.

The entire release history is available in the Archives and NuGet.