ip添加页是用了一个ListBoxTextBox两个Button
而在其他的页上则直接用当前IP对比数据库中的IP代码如下!
限制IP添加页HTML代码
<%@PageLanguage="C#"AutoEventWireup="true"CodeFile="ipaspxcs"Inherits="admin_ip"%>
<!DOCTYPEhtmlPUBLIC"//WC//DTDXHTMLTransitional//EN""
<htmlxmlns="
<headrunat="server">
<title>无标题页</title>
<linkhref="/images/newsCSS"rel="stylesheet"type="text/css"/>
</head>
<body>
<formid="form"runat="server">
<div>
<asp:SqlDataSourceID="SqlDataSource"runat="server"ConnectionString="<%$ConnectionStrings:book%>"
PRoviderName="<%$ConnectionStrings:bookProviderName%>"SelectCommand="SELECT[ip]FROM[ip]">
</asp:SqlDataSource>
<tablealign="center"style="borderright:#ccpxdotted;bordertop:#ccpxdotted;borderleft:#ccpxdotted;borderbottom:#ccpxdotted">
<tr>
<tdrowspan=""style="width:px;borderright:#ccffpxgroove;bordertop:#ccffpxgroove;borderleft:#ccffpxgroove;borderbottom:#ccffpxgroove;">
<asp:ListBoxID="iplxb"runat="server"DataSourceID="SqlDataSource"DataTextField="ip"
DataValueField="ip"Height="px"Width="px"></asp:ListBox></td>
<tdstyle="width:px;borderright:#ccffpxgroove;bordertop:#ccffpxgroove;borderleft:#ccffpxgroove;borderbottom:#ccffpxgroove;">
填写标准的IP地址到左下文本框里面然后点击按纽添加!<br/>
<asp:RegularExpressionValidatorID="RegularExpressionValidator"runat="server"ControlToValidate="iptb"
Display="Dynamic"ErrorMessage="IP地址格式不正确"ValidationExpression="([]{})([])([]{})([])([]{})([])([]{})"></asp:RegularExpressionValidator></td>
</tr>
<tr>
<tdstyle="width:px;borderright:#ccffpxgroove;bordertop:#ccffpxgroove;borderleft:#ccffpxgroove;borderbottom:#ccffpxgroove;">
<asp:LinkButtonID="LinkButton"runat="server"OnClick="LinkButton_Click">删除选中的行</asp:LinkButton></td>
</tr>
<tr>
<tdstyle="width:px;borderright:#ccffpxgroove;bordertop:#ccffpxgroove;borderleft:#ccffpxgroove;borderbottom:#ccffpxgroove;">
<asp:TextBoxID="iptb"runat="server"Width="px"></asp:TextBox></td>
<tdstyle="width:px;borderright:#ccffpxgroove;bordertop:#ccffpxgroove;borderleft:#ccffpxgroove;borderbottom:#ccffpxgroove;">
<asp:ButtonID="Button"runat="server"OnClick="Button_Click"Text="增加"Width="px"/></td>
</tr>
</table>
</div>
</form>
</body>
</html>
限制IP添加页CS代码
usingSystem;
usingSystemData;
usingSystemConfiguration;
usingSystemCollections;
usingSystemWeb;
usingSystemWebSecurity;
usingSystemWebUI;
usingSystemWebUIWebControls;
usingSystemWebUIWebControlsWebParts;
usingSystemWebUIHtmlControls;
publicpartialclassadmin_ip:SystemWebUIPage
{
protectedvoidPage_Load(objectsenderEventArgse)
{
ServerExecute("chklogaspx");
}
protectedvoidButton_Click(objectsenderEventArgse)
{
iplxbItemsAdd(iptbText);
odbinsert("insertintoip(ip)values(’"+iptbText+"’)");
}
protectedvoidLinkButton_Click(objectsenderEventArgse)
{
for(inti=;i<iplxbItemsCount;i++)
{
if(iplxbItems[i]Selected)
{
odbinsert("deletefromipwhereip=’"+iplxbSelectedItemText+"’");
iplxbItemsRemove(iplxbSelectedItemText);
}
}
}
}
被需要限制IP的页面调用页的代码
protectedvoidPage_Load(objectsenderEventArgse)
{
stringip=RequestUserHostAddressToString();
if(ConvertToInt(odbscr("selectcount(*)from[ip]whereip=’"+ip+"’"))>)
ResponseWrite("对不起您的IP被限制访问请咨询管理员");
}
}