views:

205

answers:

1

I'm using Request.UserHostAddress in a C# ASP.NET MVC web application to get the IP address of the client.

Request.UserHostAddress returns a string which is simple enough to convert into its integer form. However, this appears to be 2 levels of inefficiency because deep in the bowels of the .Net stack it probably takes the integer representation of the IP address and converts it to a string before my code converts it back to an integer.

Can I get the integer representation of the client's IPv4 address directly from .NET?

+1  A: 

Not that I know of. Are you saying you need the integer representation yourself? Surely in any display or reporting purposes, you would want to see the normal IP address notation, not the 32-bit integer representation of it. And that would result you converting it back again into a decent readable format, which is the kind of conversion you want to avoid...

Wim Hollebrandse
Yes - I need the integer representation to work with. This is not for reporting purposes.
Guy