按IP限制页面 [英] Restrict page by IP

查看:89
本文介绍了按IP限制页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在ASP / VBSCRIPT中工作,如果用户的IP不属于本地网络,我有一个拒绝访问页面的代码:

用户的IP不属于本地网络:


<%

Dim RemoteAddr

RemoteAddr = Request.ServerVariables(" REMOTE_ADDR")

if instr(RemoteAddr," ; 192.168.0")然后

Else Response.Redirect(" /Login/entry_denied.asp")

结束如果

%> ;


我需要将它应用到ASPX页面。你能帮我解释一下这个语法吗?

Working in ASP/VBSCRIPT, I have a snippet that denies access to a page if
the user''s IP does not belong to the local network:

<%
Dim RemoteAddr
RemoteAddr = Request.ServerVariables("REMOTE_ADDR")
If instr(RemoteAddr, "192.168.0") Then
Else Response.Redirect ("/Login/entry_denied.asp")
End If
%>

I need to apply this to a ASPX page. Can you help me with the syntax?

推荐答案

只需把这个逻辑放在你的ASPX中的第一个Page_Load例程中< br $>


将Dim RemoteAddr更改为:

将RemoteAddr调暗为字符串

删除< %%标签并且你很高兴去


-

David Wier

MVP / ASPInsider
http://aspnet101.com
http://iWritePro.com


" Billy Bob" < no*@home.rightnowwrote in message

news:e5 ************** @ TK2MSFTNGP03.phx.gbl ...
Just put this logic at the very first of the Page_Load routine, in your ASPX
page
change Dim RemoteAddr to:
Dim RemoteAddr as String
remove the <% %tags and you''re good to go

--
David Wier
MVP/ASPInsider
http://aspnet101.com
http://iWritePro.com

"Billy Bob" <no*@home.rightnowwrote in message
news:e5**************@TK2MSFTNGP03.phx.gbl...

在ASP / VBSCRIPT中工作时,如果用户的IP不属于本地网络,我有一个拒绝访问页面的代码片段:用户的IP不属于本地网络: br />

<%

Dim RemoteAddr

RemoteAddr = Request.ServerVariables(" REMOTE_ADDR")

如果instr(RemoteAddr," 192.168.0")那么

Else Response.Redirect(" /Login/entry_denied.asp")

结束如果

%>


我需要将其应用于ASPX页面。你能用语法帮我吗?
Working in ASP/VBSCRIPT, I have a snippet that denies access to a page if
the user''s IP does not belong to the local network:

<%
Dim RemoteAddr
RemoteAddr = Request.ServerVariables("REMOTE_ADDR")
If instr(RemoteAddr, "192.168.0") Then
Else Response.Redirect ("/Login/entry_denied.asp")
End If
%>

I need to apply this to a ASPX page. Can you help me with the syntax?



" Billy Bob" < no*@home.rightnowwrote in message

news:e5 ************** @ TK2MSFTNGP03.phx.gbl ...
"Billy Bob" <no*@home.rightnowwrote in message
news:e5**************@TK2MSFTNGP03.phx.gbl...

在ASP / VBSCRIPT中工作时,如果用户的IP不属于本地网络,我有一个拒绝访问页面的代码片段:用户的IP不属于本地网络: br />

<%

Dim RemoteAddr

RemoteAddr = Request.ServerVariables(" REMOTE_ADDR")

如果instr(RemoteAddr," 192.168.0")那么

Else Response.Redirect(" /Login/entry_denied.asp")

结束如果

%>


我需要将其应用于ASPX页面。你能用语法帮我吗?
Working in ASP/VBSCRIPT, I have a snippet that denies access to a page if
the user''s IP does not belong to the local network:

<%
Dim RemoteAddr
RemoteAddr = Request.ServerVariables("REMOTE_ADDR")
If instr(RemoteAddr, "192.168.0") Then
Else Response.Redirect ("/Login/entry_denied.asp")
End If
%>

I need to apply this to a ASPX page. Can you help me with the syntax?



private void Page_Load(object sender,System.EventArgs e)

{

如果

(!Request.ServerVariables [" REMOTE_ADDR"]。ToString()。StartsWith(" 192.168.0"))

{

Response.Redirect (" /Login/entry_denied.asp" ;, false);

}

}

-
http://www.markrae.net


private void Page_Load(object sender, System.EventArgs e)
{
if
(!Request.ServerVariables["REMOTE_ADDR"].ToString().StartsWith("192.168.0"))
{
Response.Redirect ("/Login/entry_denied.asp", false);
}
}
--
http://www.markrae.net

还有一个无关的Else...


如果放在Page_Load事件中,这应该覆盖它:


Dim RemoteAddr as String = Request.ServerVariables(" REMOTE_ADDR")

if instr(RemoteAddr," 192.168.0")然后

Response.Redirect (< /Login/entry_denied.asp")

结束如果


Mark'的代码更简单。


Juan T. Llibre,asp.net MVP

asp.net faq: http://asp.net.do/faq/

foros de asp.net,en espa?ol: http://asp.net.do/foros/

======================================

David Wier < da ******* @ davidwier.nospam.com写信息

news:u6 ************** @ TK2MSFTNGP02.phx.gbl。 ..
There''s also an extraneous "Else"...

This should cover it, if placed in the Page_Load event :

Dim RemoteAddr as String = Request.ServerVariables("REMOTE_ADDR")
If instr(RemoteAddr, "192.168.0") Then
Response.Redirect ("/Login/entry_denied.asp")
End If

Mark''s code is simpler, though.


Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en espa?ol : http://asp.net.do/foros/
======================================
"David Wier" <da*******@davidwier.nospam.comwrote in message
news:u6**************@TK2MSFTNGP02.phx.gbl...

只需将此逻辑放在Page_Load例程的第一个,在ASPX页面中

将Dim RemoteAddr更改为:

Dim RemoteAddr as String

删除< %%标签,你很高兴


-

David Wier

MVP / ASPInsider
http:// aspnet101.com
http://iWritePro.com


" Billy Bob" < no*@home.rightnow在消息新闻中写道:e5 ************** @ TK2MSFTNGP03.phx.gbl ...
Just put this logic at the very first of the Page_Load routine, in your ASPX page
change Dim RemoteAddr to:
Dim RemoteAddr as String
remove the <% %tags and you''re good to go

--
David Wier
MVP/ASPInsider
http://aspnet101.com
http://iWritePro.com

"Billy Bob" <no*@home.rightnowwrote in message news:e5**************@TK2MSFTNGP03.phx.gbl...

>在ASP / VBSCRIPT中工作,如果用户的IP不属于本地网络,我有一个拒绝访问页面的片段:

<%
Dim RemoteAddr
RemoteAddr = Request.ServerVariables(REMOTE_ADDR)
如果instr(RemoteAddr,192.168.0)那么
Else Response.Redirect(" /登录/ entry_denied.asp")
结束如果
%>

我需要将其应用于ASPX页面。你能用语法帮我吗?
>Working in ASP/VBSCRIPT, I have a snippet that denies access to a page if the user''s IP does not
belong to the local network:

<%
Dim RemoteAddr
RemoteAddr = Request.ServerVariables("REMOTE_ADDR")
If instr(RemoteAddr, "192.168.0") Then
Else Response.Redirect ("/Login/entry_denied.asp")
End If
%>

I need to apply this to a ASPX page. Can you help me with the syntax?




这篇关于按IP限制页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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