如何将主机Web服务器的IP地址转换为Session变量? [英] How can I get the IP address of the host Web Server into a Session variable?

查看:66
本文介绍了如何将主机Web服务器的IP地址转换为Session变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我的安装网站上的Web服务器目前没有这样的情况

有一个公开注册的域名与现场。这个

要求用户使用IP地址从远程(LAN外)

浏览器访问该站点,如 http://192.35.78.234


目前在我的代码中我使用以下语法来获取根网站路径

然后我将其作为前缀添加到外部文档中的图像和链接

(Excel文件),以便HTML电子邮件的收件人或其中一个电子表格

可以解析图像或点击电子表格链接查看网站上的页面

$

Dim strRootWeb As String = Me.Request.Headers.Item(" Host")。ToString

strRootWeb =" http://" + strRootWeb

Session.Add(" RootWeb",strRootWeb)


然后,对于外部文档中的工作链接,我将执行以下操作:


公共strRootWeb =会话(" RootWeb")

strRootWeb& " /Common/PageView.aspx


但是,如果Web服务器的名称不公开地在DNS服务器上注册
,则不起作用。 />

感谢您解决Web服务器根目录IP地址的任何帮助。

解决方案

" John Kotuby" ; < jk ******* @ comcast.netwrote in message

news:%2 **************** @ TK2MSFTNGP06.phx.gbl ...


不确定这是否是您想要的,但根据您的

帖子的主题,您可以获得IP地址主机Web服务器进入Session

变量如下:

Session [" HostIP"] = Request.ServerVariables [" LOCAL_ADDR"]。ToString ();

-

Mark Rae

ASP.NET MVP
http://www.markrae.net


感谢您的光临回复Mark,


我认为这将为我提供运行

Web应用程序的服务器盒的实际IP地址。如果直接连接到互联网,这对我有用。

但是,在这种情况下,Web服务器是在防火墙后面并且是

通过NAT访问。


我真正想要的是在

请求中使用的公共IP地址,以便到达路由器然后找到防火墙后面的服务器。


我认为它包含在HttpRequest对象的某个地方,只是

作为Me.Request.Headers.Item (主机)。ToString根据客户端的请求返回

根网站的字符串。


当浏览器发出< a rel =nofollowhref =http://www.url.comtarget =_ blank> http://www.url.com 即

立即转换通过公共DNS服务器到IP地址。这是我想要抓住的公共IP地址,无论Web服务器托管什么,我们的应用程序都是b $ b。我一直在寻找包含IP

地址的房产,但似乎无法在文档中找到它。


谢谢...

" Mark Rae [MVP]" < ma ** @ markNOSPAMrae.netwrote in message

news:ec ************** @ TK2MSFTNGP06.phx.gbl ...
< blockquote class =post_quotes>
" John Kotuby" < jk ******* @ comcast.netwrote in message

news:%2 **************** @ TK2MSFTNGP06.phx.gbl ...


不确定这是否是您想要的,但根据您的

帖子的主题,您可以获得IP地址主机Web服务器进入Session

变量如下:

Session [" HostIP"] = Request.ServerVariables [" LOCAL_ADDR"]。ToString ();


-

Mark Rae

ASP.NET MVP
http://www.markrae.net



如果防火墙(或负载均衡器)正在进行nat转换(它应该是
),那么它就不可用(因为只有防火墙知道它)。


你最好的选择是将ipaddress添加到web.config作为设置


- 布鲁斯(sqlwork.com)

" John Kotuby写道:


感谢回复标记,


我认为这会给我实际的服务器IP地址

Web应用程序正在运行。如果直接连接到互联网,这对我有用。

但是,在这种情况下,Web服务器是在防火墙后面并且是

通过NAT访问。


我真正想要的是在

请求中使用的公共IP地址,以便到达路由器然后找到防火墙后面的服务器。


我认为它包含在HttpRequest对象的某个地方,只是

作为Me.Request.Headers.Item (主机)。ToString根据客户端的请求返回

根网站的字符串。


当浏览器发出< a rel =nofollowhref =http://www.url.comtarget =_ blank> http://www.url.com 即

立即转换通过公共DNS服务器到IP地址。这是我想要抓住的公共IP地址,无论Web服务器托管什么,我们的应用程序都是b $ b。我一直在寻找包含IP

地址的房产,但似乎无法在文档中找到它。


谢谢...


" Mark Rae [MVP]" < ma ** @ markNOSPAMrae.netwrote in message

news:ec ************** @ TK2MSFTNGP06.phx.gbl ...
< blockquote class =post_quotes>
" John Kotuby" < jk ******* @ comcast.netwrote in message

news:%2 **************** @ TK2MSFTNGP06.phx.gbl ...


不确定这是否是您想要的,但根据您的

帖子的主题,您可以获得IP地址主机Web服务器进入Session

变量如下:

Session [" HostIP"] = Request.ServerVariables [" LOCAL_ADDR"]。ToString ();

-

Mark Rae

ASP.NET MVP
http://www.markrae.net




Hi all,

I have a situation where a Web Server at an install site does not currently
have a publically registered Domain Name associated with the site. This
requires that the a user access the site from a remote (outside the LAN)
browser using the IP address, as in http://192.35.78.234 .

Currently in my code I use the following syntax to obtain the Root Web path
which I then append as a prefix to Images and Links in external documents
(Excel files) so the recipient of an HTML Email or one of the spreadsheets
can both resolve the images or click on a spreadsheet link to view a page on
the site.

Dim strRootWeb As String = Me.Request.Headers.Item("Host").ToString
strRootWeb = "http://" + strRootWeb
Session.Add("RootWeb", strRootWeb)

Then for a working link in an external document I will do something like:

Public strRootWeb = Session("RootWeb")
strRootWeb & "/Common/PageView.aspx

But this does not work if the name of the Web Server is not publically
registered with DNS servers.

Thanks for any help on resolving the IP address of a Web Server root.

解决方案

"John Kotuby" <jk*******@comcast.netwrote in message
news:%2****************@TK2MSFTNGP06.phx.gbl...

Not sure if this is what you want or not but, based on the subject of your
post, you can get the IP address of the host web server into a Session
variable like this:

Session["HostIP"] = Request.ServerVariables["LOCAL_ADDR"].ToString();
--
Mark Rae
ASP.NET MVP
http://www.markrae.net


Thanks for the reply Mark,

I think that will give me the actual IP address of the Server box that the
Web Application is running on. That would work for me if the was directly
connected to the Internet.
However, in this situation, the Web Server is behind a firewall and being
accessed via NAT.

What I am really looking for is the Public IP Address that is used in the
request to get to the Router that then finds the Server behind the firewall.

I am thinking that it is contained somewhere in the HttpRequest object just
as the Me.Request.Headers.Item("Host").ToString returns the string for the
Root Web as requested by the client.

When the browser sends out a request for http://www.url.com that is
immediately converted by a public DNS server to an IP address. It is that
public IP address that I seek to grab, not matter what Web server is hosting
our application. I have been looking for the property that contains the IP
address but can''t seem to find it in the documentation.

Thanks...
"Mark Rae [MVP]" <ma**@markNOSPAMrae.netwrote in message
news:ec**************@TK2MSFTNGP06.phx.gbl...

"John Kotuby" <jk*******@comcast.netwrote in message
news:%2****************@TK2MSFTNGP06.phx.gbl...

Not sure if this is what you want or not but, based on the subject of your
post, you can get the IP address of the host web server into a Session
variable like this:

Session["HostIP"] = Request.ServerVariables["LOCAL_ADDR"].ToString();
--
Mark Rae
ASP.NET MVP
http://www.markrae.net



if the firewall (or load balancer) is doing nat translation (which it should
be), then its not available (as only the firewall knows it).

your best bet is to add to the ipaddress to the web.config as a setting

-- bruce (sqlwork.com)
"John Kotuby" wrote:

Thanks for the reply Mark,

I think that will give me the actual IP address of the Server box that the
Web Application is running on. That would work for me if the was directly
connected to the Internet.
However, in this situation, the Web Server is behind a firewall and being
accessed via NAT.

What I am really looking for is the Public IP Address that is used in the
request to get to the Router that then finds the Server behind the firewall.

I am thinking that it is contained somewhere in the HttpRequest object just
as the Me.Request.Headers.Item("Host").ToString returns the string for the
Root Web as requested by the client.

When the browser sends out a request for http://www.url.com that is
immediately converted by a public DNS server to an IP address. It is that
public IP address that I seek to grab, not matter what Web server is hosting
our application. I have been looking for the property that contains the IP
address but can''t seem to find it in the documentation.

Thanks...
"Mark Rae [MVP]" <ma**@markNOSPAMrae.netwrote in message
news:ec**************@TK2MSFTNGP06.phx.gbl...

"John Kotuby" <jk*******@comcast.netwrote in message
news:%2****************@TK2MSFTNGP06.phx.gbl...

Not sure if this is what you want or not but, based on the subject of your
post, you can get the IP address of the host web server into a Session
variable like this:

Session["HostIP"] = Request.ServerVariables["LOCAL_ADDR"].ToString();
--
Mark Rae
ASP.NET MVP
http://www.markrae.net




这篇关于如何将主机Web服务器的IP地址转换为Session变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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