如何在C#中获取响应URL的IP地址 [英] How to get IP address of responsed url in C#

查看:167
本文介绍了如何在C#中获取响应URL的IP地址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的网站上使用了支付网关。我想只允许一些IP来存储数据,所以

我想得到安全的url ip地址。我希望获得响应的IP地址网址。当我从网关回到我的网站时,我想检查响应的IP地址(获取IP地址)。

I used payment gateway in my site.I want to allow just some IP for storing data, so
I want to get responsed url ip address for security.I want to get IP Address of responsed url. When I come back to my site from gateway I want to check responsed IP address(getway IP Address).

推荐答案

请参阅我对该问题的评论。



如果您有一些URI并想知道IP地址,则没有一对一的通信,因为任何主机都可以提供多个IP地址。这与ASP.NET或HTTP无关,是DNS的责任。



例如:

Please see my comment to the question.

If you have some URI and want to know IP address, there is no one-to-one correspondence, as any host can serve multiple IP addresses. This is not related to ASP.NET or HTTP and is the responsibility of DNS.

For example:
System.Net.IPAddress[] addresses = System.Net.Dns.GetHostAddresses("www.CodeProject.com");





注意,这是一个IP地址数组,而不仅仅是一个。



如果你需要获得一个IP地址客户端,更确切地说,是HTTP请求(不是响应,因为你总是在服务器端知道并且它实际上没有使用它),你可以使用 HttpRequest.ServerVariables [REMOTE_ADDR];

http:/ /msdn.microsoft.com/en-us/library/system.web.httprequest.servervariables.aspx [ ^ ]。



请参阅: HT tp://www.w3schools.com/asp/coll_servervariables.asp [ ^ ]。



-SA



Note, this is an array of IP addresses, not just one.

If you need to get an IP address of the client, more exactly, of the HTTP request (not response, as you always know it on the server side and it is not actually used), you can use HttpRequest.ServerVariables["REMOTE_ADDR"];
http://msdn.microsoft.com/en-us/library/system.web.httprequest.servervariables.aspx[^].

Please see also: http://www.w3schools.com/asp/coll_servervariables.asp[^].

—SA


这篇关于如何在C#中获取响应URL的IP地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆