473,385 Members | 1,333 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Restrict page by IP

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?

Jun 7 '07 #1
11 1554
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...
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?

Jun 7 '07 #2
"Billy Bob" <no*@home.rightnowwrote in message
news:e5**************@TK2MSFTNGP03.phx.gbl...
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)
{
if
(!Request.ServerVariables["REMOTE_ADDR"].ToString().StartsWith("192.168.0"))
{
Response.Redirect ("/Login/entry_denied.asp", false);
}
}
--
http://www.markrae.net

Jun 7 '07 #3
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...
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...
>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?


Jun 7 '07 #4
I get the error: Only Content controls are allowed directly in a content
page that contains Content controls.
for the line Dim RemoteAddr as String

I am way out of my comfort zone.... anything else?
Bill


"David Wier" <da*******@davidwier.nospam.comwrote in message
news:u6**************@TK2MSFTNGP02.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...
>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?

Jun 7 '07 #5
My mistake on the original code, should be:

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


"Juan T. Llibre" <no***********@nowhere.comwrote in message
news:ud**************@TK2MSFTNGP06.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...
>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...
>>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?


Jun 7 '07 #6
Yup. It *was* "extraneous".

:-)

Did you try Mark's code ? That should work.

Since you're using VB.NET, and not C#,
which he used for the sample, here it is in VB.NET :

Private Sub Page_Load(sender As Object, e As System.EventArgs)
If Not Request.ServerVariables("REMOTE_ADDR").ToString(). StartsWith("192.168.0") Then
Response.Redirect("/Login/entry_denied.asp", False)
End If
End Sub

Try it...


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/
======================================
"Billy Bob" <no*@home.rightnowwrote in message news:ej**************@TK2MSFTNGP04.phx.gbl...
My mistake on the original code, should be:

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


"Juan T. Llibre" <no***********@nowhere.comwrote in message
news:ud**************@TK2MSFTNGP06.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...
>>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...
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?



Jun 7 '07 #7
"Billy Bob" <no*@home.rightnowwrote in message
news:%2***************@TK2MSFTNGP06.phx.gbl...
>I get the error: Only Content controls are allowed directly in a content
page that contains Content controls.
for the line Dim RemoteAddr as String
1) Are you using MasterPages...?

2) Are you writing your server-side code in-line or in separate code
files...?
--
http://www.markrae.net

Jun 7 '07 #8
Lots of good sugegstions, if it were me I would create an httpmodule that
checks the IPs in the beginRequest event. That way it applies to all pages
and you dont have to put it anywhere else. Code it once, and use it
whereever

http://www.devx.com/dotnet/Article/6962/0/page/1
Regards

John Timney (MVP)
http://www.johntimney.com
http://www.johntimney.com/blog
"Billy Bob" <no*@home.rightnowwrote in message
news:e5**************@TK2MSFTNGP03.phx.gbl...
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?

Jun 7 '07 #9
>>I get the error: Only Content controls are allowed directly in a content
>>page that contains Content controls.
for the line Dim RemoteAddr as String

1) Are you using MasterPages...?

2) Are you writing your server-side code in-line or in separate code
files...?

1) MasterPages, yes.
2) ServerSide code is in a separate file, filename.aspx.cs

Thank you for your time. Apparently I didn't provide enough information with
my first request.

Jun 7 '07 #10
"Billy Bob" <no*@home.rightnowwrote in message
news:eB**************@TK2MSFTNGP06.phx.gbl...
>>>I get the error: Only Content controls are allowed directly in a content
page that contains Content controls.
for the line Dim RemoteAddr as String

1) Are you using MasterPages...?

2) Are you writing your server-side code in-line or in separate code
files...?


1) MasterPages, yes.
2) ServerSide code is in a separate file, filename.aspx.cs

In which case, if you just want the IP restriction to apply to certain
content pages, put the code in the Page_Load event behind the individual
content page(s).

Or, if you want it to apply to all content pages, put it in the MasterPage's
Page_Load event - however, if your entry_denied page is also a content page,
you'll get stuck in a loop... :-)

If you want it to apply to the entire site, follow John's suggestion.
--
http://www.markrae.net

Jun 7 '07 #11
Thank you.
Jun 7 '07 #12

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Paul | last post by:
Hi all, at present I I've built a website which can be updated by admin and users. My problem, I've combined "log in" and "access levels" to restrict access to certain pages, using the built...
28
by: gc | last post by:
Hi, What is the purpose of the restrict keyword? gc
7
by: tweak | last post by:
Can someone give me a short example as how to best use this keyword in your code? This is my understanding: by definition restrict sounds like it is suppose to restrict access to memory...
2
by: Jaydeep | last post by:
Hi, I want to restrict any user if he types url directly in the browser without logging to my site. Like for example user should not see any listing page of my web site by typing url...
12
by: Me | last post by:
I'm trying to wrap my head around the wording but from what I think the standard says: 1. it's impossible to swap a restrict pointer with another pointer, i.e. int a = 1, b = 2; int *...
21
by: Niu Xiao | last post by:
I see a lot of use in function declarations, such as size_t fread(void* restrict ptr, size_t size, size_t nobj, FILE* restrict fp); but what does the keyword 'restrict' mean? there is no...
2
by: imtmub | last post by:
Hi, I designed website for Magazine and it contains some jpeg pictures, articles etc., Now i m planning to restrict JPEG file on my page saving on to their local system, User can view but they...
3
by: =?Utf-8?B?R1ROMTcwNzc3?= | last post by:
Hi there, I've got the standard Dreamweaver restrict access to page behaviour below – <% ' *** Restrict Access To Page: Grant or deny access to this page MM_authorizedUsers="1,2,3"...
0
by: copx | last post by:
Restrict keyword questions How far does the guarantee that an object is not accessed through another pointer go? I mean, all examples I have seen are simple stuff like: int f (int *restrict x,...
23
by: raashid bhatt | last post by:
what is restrict keyword used for? eg int *restrict p;
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.