I think of this as a message book. The specific ideas may not be good. I just hope there are better methods!
The IP add page uses a ListBox, Textbox, and two buttons. On other pages, the current IP address is used to compare the IP address in the database,CodeAs follows!
Restrict IP addresses to add HTML code
<% @ Page Language = "C #" autoeventwireup = "true" codefile = "ip. aspx. cs" inherits = "admin_ip" %>
<! Doctype HTML public "-// W3C // dtd xhtml 1.0 transitional // en" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<HTML xmlns = "http://www.w3.org/1999/xhtml">
<Head runat = "server">
<Title> No title page </title>
<Link href = "../images/news.css" rel = "stylesheet" type = "text/CSS"/>
</Head>
<Body>
<Form ID = "form1" runat = "server">
<Div>
<Asp: sqldatasource id = "sqldatasource1" runat = "server" connectionstring = "<% $ connectionstrings: Book %>"
Providername = "<% $ connectionstrings: Book. providername %>" selectcommand = "select [IP] from [IP]">
</ASP: sqldatasource>
<Table align = "center" style = "border-Right: # 0066cc 1px dotted; border-top: # 0066cc 1px dotted; border-left: # 0066cc 1px dotted; border-bottom: # 0066cc 1px dotted ">
<Tr>
<TD rowspan = "2" style = "width: 100px; border-Right: #33 CCFF 1px groove; border-top: #33 CCFF 1px groove; border-left: #33 CCFF 1px groove; border-bottom: #33 CCFF 1px groove; ">
<Asp: ListBox id = "iplxb" runat = "server" datasourceid = "sqldatasource1" datatextfield = "ip"
Datavaluefield = "ip" Height = "194px" width = "153px"> </ASP: ListBox> </TD>
<TD style = "width: 100px; border-Right: #33 CCFF 1px groove; border-top: #33 CCFF 1px groove; border-left: #33 CCFF 1px groove; border-bottom: #33 CCFF 1px groove; ">
Enter the standard IP address in the lower-left text box and click "add! <Br/>
<Asp: regularexpressionvalidator id = "regularexpressionvalidator1" runat = "server" controltovalidate = "iptb"
Display = "dynamic" errormessage = "Incorrect IP address format" validationexpression = "([0-9] {2, 3}) ([.]) ([0-9] {1, 3}) ([.]) ([0-9] {1, 3}) ([.]) ([0-9] {1, 3}) "> </ASP: regularexpressionvalidator> </TD>
</Tr>
<Tr>
<TD style = "width: 100px; border-Right: #33 CCFF 1px groove; border-top: #33 CCFF 1px groove; border-left: #33 CCFF 1px groove; border-bottom: #33 CCFF 1px groove; ">
<Asp: linkbutton id = "linkbutton1" runat = "server" onclick = "linkbutton1_click"> Delete selected rows </ASP: linkbutton> </TD>
</Tr>
<Tr>
<TD style = "width: 100px; border-Right: #33 CCFF 1px groove; border-top: #33 CCFF 1px groove; border-left: #33 CCFF 1px groove; border-bottom: #33 CCFF 1px groove; ">
<Asp: textbox id = "iptb" runat = "server" width = "150px"> 61.139.33.22 </ASP: textbox> </TD>
<TD style = "width: 100px; border-Right: #33 CCFF 1px groove; border-top: #33 CCFF 1px groove; border-left: #33 CCFF 1px groove; border-bottom: #33 CCFF 1px groove; ">
<Asp: button id = "button1" runat = "server" onclick = "button#click" text = "add" width = "80px"/> </TD>
</Tr>
</Table>
</Div>
</Form>
</Body>
</Html>
Restrict IP address add page CS code
Using system;
Using system. Data;
Using system. configuration;
Using system. collections;
Using system. Web;
Using system. Web. Security;
Using system. Web. UI;
Using system. Web. UI. webcontrols;
Using system. Web. UI. webcontrols. webparts;
Using system. Web. UI. htmlcontrols;
Public partial class admin_ip: system. Web. UI. Page
{
Protected void page_load (Object sender, eventargs E)
{
Server. Execute ("chklog. aspx ");
}
Protected void button#click (Object sender, eventargs E)
{
Iplxb. Items. Add (iptb. Text );
ODB. insert ("insert into IP (IP) values ('" + iptb. Text + "')");
}
Protected void linkbutton#click (Object sender, eventargs E)
{
For (INT I = 0; I <iplxb. Items. Count; I ++)
{
If (iplxb. items [I]. Selected)
{
ODB. insert ("delete from IP where IP = '" + iplxb. selecteditem. Text + "'");
Iplxb. Items. Remove (iplxb. selecteditem. Text );
}
}
}
}
Code of the page call page to be restricted by IP addresses
protected void page_load (Object sender, eventargs e)
{< br> string IP = request. userhostaddress. tostring ();
If (convert. toint32 (ODB. SCR ("select count (*) from [IP] Where IP = '" + IP + "'")> 0)
response. write ("sorry, your IP address is restricted for access, please consult the Administrator");
}< BR >}