C# SetHttpHandler

Hello forums, I am probably missing something simple, but I’m finding myself in an odd place. I’ve been having fun with the Mono v2 Runtime over the past few weeks, and started rewriting a couple of my own projects that I formerly began writing in Lua. One of the first things I went to work on was the webserver portion of the resource, but I had trouble getting the SetHttpHandler native to do anything useful. I don’t think it does anything at all, because even after being called, the resource route always returns “Not found.” similar to other resources that do not set a handler. I was hoping there were some working examples somewhere to prove that this is indeed possible, however a quick search on GitHub didn’t give me much to work with.

For clarity, this is what I’m currently working with:

public class WebserverMain : BaseScript
{
    private void RegisterWebHandler()
    {
        Debug.WriteLine("SetHttpHandler");
        Natives.SetHttpHandler(new Action<dynamic, dynamic>(async (req, res) => {
            Debug.WriteLine($"Request received from: {req.address}");
        }));
    }
}

When the resource is started, I get a “SetHttpHandler” log but never any “Request received from…” logs when making a request to /my-resource-name.

Any help or clarity is greatly appreciated :pray: I looked in many places to see if anyone else also ran into this problem.

Make sure when you’re posting the request, to follow the format http://ip:port/resourceName/..., other than that, your code looks fine and should trigger

Yep, that’s what I’ve been doing. Here’s some examples:

Have you tried the actual ip? or 127.0.0.1?

I’m running this server on my local machine, so localhost it is. I just tried 127.0.0.1 with the same results, I don’t think FXServer cares about the Host header though.

I swear I had the same issue, I ended up using my public ip I found from google in there and it worked lol

Tell you what, I can try my private IP, but I’m not port forwarded through my public - still got the same result on private.

I can also try putting it on a legitimate server but then I have to update the server for the latest rt2 pilot date and I figure it’ll give the same result anyways.

Have you tried the same thing on rt1?

Works fine in rt1, so… rt2 bug? I’m using the same code.


Certainly, there’s no reason why it would work in rt1, and not in rt2, I’d report it

I appreciate the sanity check, I just made an issue on the RT2 repo: SetHttpHandler doesn't work on RT2, works on RT1 · Issue #41 · thorium-cfx/mono_v2_get_started · GitHub

1 Like

For me is working well: