开发者

Programmer using Request.UserHostAddress wants an integer

开发者 https://www.devze.com 2022-12-15 04:47 出处:网络
I\'m using Request.UserHo开发者_JAVA技巧stAddress in a C# ASP.NET MVC web application to get the IP address of the client.

I'm using Request.UserHo开发者_JAVA技巧stAddress 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?


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...

0

精彩评论

暂无评论...
验证码 换一张
取 消