How to get client IP address or any info from current http context during processing global events

Greg Ryjikh asked on April 13, 2023 06:11

We are converting site from Kentico 11 portal engine to Kentico 13 Core. One of function of old site is submitting data to external payment gateway during donation form submission. That was handled by Kentico global bizform events and we are trying to do the same in Kentico 13.

The problem is that standard method of handling global events https://docs.xperience.io/custom-development/handling-global-events relies on using custom modules which are not part of .NET Core pipeline and there is no way to use dependency injection to pass to custom module some extra data like IHttpContextAccessor. Note that those objects or extra services can passed to Kentico custom services https://docs.xperience.io/custom-development/decorating-system-services

In particular in our case payment gateway provider requires client IP address to be send to them as part of payment process. I can not find any way to get client IP address during handling Kentico 13 global event like BizFormItemEvents.Insert.Before because it does not have access to the current HTTP context (it was easily accessible from Kentico custom modules before). It seems to be only possible when those global events could be handled inside .NET pipeline for example in controller or middleware.

Simple question is how I can find client IP address while processing global events in Kentico? I would be happy with any working suggestion for immediate use but it seems to me that Kentico will need to incorporate events handling into .NET Core processing. Otherwise many other features easily available in other places can not be used there.

P.S. I even tried to add calls to BizFormItemEvents.Insert.Before += FormItem_InsertBeforeHandler; inside various middleware steps but that didn't work (nothing was loaded on the site and no errors produced).

Recent Answers


Rory Aherne answered on April 13, 2023 10:34

I'm also looking for an answer to this. I wish there was a way we could upvote and follow other users questions.

0 votesVote for this answer Mark as a Correct answer

Rory Aherne answered on April 17, 2023 09:47

Perfect timing for this article to come out with the answer:

https://devnet.kentico.com/articles/building-an-integration-(stripe)-part-3-helpers-and-event-handlers

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.