473,386 Members | 1,736 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,386 software developers and data experts.

Best way to check IP address in a lot of pages

I'm going to have an admin section to a site I'm developing using ASP.NET C#

I want to restrict access to this directory based on username and password
(I've got that bit done) but also upon the IP address of the user accessing
it. I only want my IP to get access to this directory but my IP may change
from time to time so this should be easy to change in the code - ideally in
one place.

Is this possible and if so what is the best way to do it?
Nov 18 '05 #1
4 1406
Can you put the allowable IPs in the web.config?

"Andrew Banks" <ba****@nojunkblueyonder.co.uk> wrote in message
news:BK*********************@news-text.cableinet.net...
I'm going to have an admin section to a site I'm developing using ASP.NET C#
I want to restrict access to this directory based on username and password
(I've got that bit done) but also upon the IP address of the user accessing it. I only want my IP to get access to this directory but my IP may change
from time to time so this should be easy to change in the code - ideally in one place.

Is this possible and if so what is the best way to do it?

Nov 18 '05 #2
That's what I was thinking. I've got my authorisation set to forms in their
and that's working fine for this directory, I just want to add the IP as an
extra measure.

Is this possibe anyone?

"Nick" <fr**@here.there> wrote in message
news:u3**************@tk2msftngp13.phx.gbl...
Can you put the allowable IPs in the web.config?

"Andrew Banks" <ba****@nojunkblueyonder.co.uk> wrote in message
news:BK*********************@news-text.cableinet.net...
I'm going to have an admin section to a site I'm developing using ASP.NET
C#

I want to restrict access to this directory based on username and

password (I've got that bit done) but also upon the IP address of the user

accessing
it. I only want my IP to get access to this directory but my IP may change from time to time so this should be easy to change in the code - ideally

in
one place.

Is this possible and if so what is the best way to do it?


Nov 18 '05 #3
Well you've got the UserHostAddress in HttpRequest which gives the IP of the
client for the current Session. In the page that requires further
authentication, simply check this value with the list of allowable IPs,
possibly loaded from the web.config or elsewhere.

"Andrew Banks" <ba****@nojunkblueyonder.co.uk> wrote in message
news:Z0*********************@news-text.cableinet.net...
That's what I was thinking. I've got my authorisation set to forms in their and that's working fine for this directory, I just want to add the IP as an extra measure.

Is this possibe anyone?

"Nick" <fr**@here.there> wrote in message
news:u3**************@tk2msftngp13.phx.gbl...
Can you put the allowable IPs in the web.config?

"Andrew Banks" <ba****@nojunkblueyonder.co.uk> wrote in message
news:BK*********************@news-text.cableinet.net...
I'm going to have an admin section to a site I'm developing using ASP.NET
C#

I want to restrict access to this directory based on username and password (I've got that bit done) but also upon the IP address of the user

accessing
it. I only want my IP to get access to this directory but my IP may change from time to time so this should be easy to change in the code -

ideally in
one place.

Is this possible and if so what is the best way to do it?



Nov 18 '05 #4
I don't think you can do this as a built in feature of asp.net. However,
you should be able to easily add the IP check into your forms authentication
code. Add a key to your web.config file with the IP Address:

<appSettings>
<add key="AdminIPAddress" value="a.b.c.d" />
</appSettings>

In the login check, check the remote IP Address against the allowed IP
Address:

string remoteIP = Request.ServerVariables["remote_addr"];
string allowedIP =
System.Configuration.ConfigurationSettings.AppSett ings["AdminIPAddress"];

if (remoteIP == allowedIP)
{
bool isAuthenticated = FormsAuthentication.Authenticate(username,
password);
if (isAuthenticated)
{
// User logged in successfully and IP Address is valid
}
else
{
// User login failed, but IP Address is valid
}
}
else
{
// User login failed. IP Address is invalid
}

Hope this helps,

Mun

--
Munsifali Rashid
http://www.munsplace.com/


"Andrew Banks" <ba****@nojunkblueyonder.co.uk> wrote in message
news:Z0*********************@news-text.cableinet.net...
That's what I was thinking. I've got my authorisation set to forms in their and that's working fine for this directory, I just want to add the IP as an extra measure.

Is this possibe anyone?



Nov 18 '05 #5

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

Similar topics

5
by: FLEB | last post by:
I'm working on a logon system, something generic and modular, as a part of a few ideas I have running. I'm just wondering, though, what is the best way to keep a user logged in authentically...
5
by: TG | last post by:
This is more of a pain than I thought it would be. I need a simple code segment to determine whether a browser accepts cookies or not. When I pass variables between pages when cookies are turned...
131
by: Peter Foti | last post by:
Simple question... which is better to use for defining font sizes and why? px and em seem to be the leading candidates. I know what the general answer is going to be, but I'm hoping to ultimately...
136
by: Matt Kruse | last post by:
http://www.JavascriptToolbox.com/bestpractices/ I started writing this up as a guide for some people who were looking for general tips on how to do things the 'right way' with Javascript. Their...
4
by: Andrew Banks | last post by:
I'm going to have an admin section to a site I'm developing using ASP.NET C# I want to restrict access to this directory based on username and password (I've got that bit done) but also upon the...
12
by: Perre Van Wilrijk | last post by:
Hi there, When I started using VB6, I used to write classes with properties and functions as following ... Private lngf1 As Long Private strf2 As String Public Property Get f1() As Long...
1
by: LilC | last post by:
I'm creating an application that has a standard layout for all pages. The information that is displayed in the layout will be dynamic based on the user that is logged in. Thus when a page is...
7
by: h7qvnk7q001 | last post by:
I'm trying to implement a simple server-side form validation (No Javascript). If the user submits a form with errors, I want to redisplay the same form with the errors highlighted. Once the form...
13
by: Justin.Voelker | last post by:
Hello Everyone: I am in search of an easier way to develop pages. My most current website, www.Base2WebDesign.com, has the exact same layout throughout the entire site. Right now I use a...
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: 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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.