How to make sure HTTP request is local when using HttpListener

I am using HttpListener

. However, I only want to handle requests that come up locally and not from another computer / server.

How would I programmatically check if an incoming request is local? Do I need to use some of the HttpListenerRequest

members?

+2


source to share


2 answers


Refer to RemoteEndPoint

property
if the remote request address is 127.0.0.1

.



+1


source


HttpListenerRequest

has a property IsLocal

that should contain this information as well. However, it returns false

on my computer. Mirroring the original code, it seems that it has something to do with the property IsLocal

using the code:

    return this.LocalEndPoint.Address == this.RemoteEndPoint.Address;

      

when possible, it should use code in a property (not available) InternalIsLocal

that:



    return this.LocalEndPoint.Address.Equals(this.RemoteEndPoint.Address);

      

(This expression returns true

for my situation). Using this approach may be preferable so that your code does not depend on IPv4 address since the transition is made to IPv6.

+5


source







All Articles