How to get the IP address of the user in the MVC lock (monorail)?

In the action of the CastleMVC application controller, how can I get the user's IP address?

I think in asp.net mvc it will be Request.ServerVariables["REMOTE_ADDR"] , but I cannot find the equivalent in Castle.

(I know about a potential proxy problem, etc., the address reported in the request is ok)

+4
source share
2 answers

Monorail lock, as well as ASP.NET MVC, serve as an elegant MVC wrapper on top of the ASP.NET runtime.

Thus, everything that can be done using the ASP.NET runtime (with the exception of WebForms-specific things like ViewState) can also be done using ASP.NET MVC and with monorail.

So, you can always grab the current HttpContext ASP.NET using the static HttpContext.Current method.

In Monorail, you can also use the IEngineContext.UnderlyingContext property to access ASP.NET HttpContext.

In particular, in Monorail, you can capture the client IP address using the convenience property UserHostAddress for the current IRequest.

eg. inside controller action:

 var clientIP = Request.UserHostAddress; 
+6
source

I believe my:

 HttpContext.Request.ServerVariables["REMOTE_ADDR"] 
+3
source

Source: https://habr.com/ru/post/1308089/


All Articles