国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > .NET > 正文

ASP.net 做的IP 訪問限制

2024-07-10 13:10:22
字體:
來源:轉載
供稿:網友

  偶做留言本的時候想起做這么個,具體思路也許不好,做出來只是拋磚引玉,希望有更好的方法!

  ip添加頁是用了一個listbox, textbox,兩個button,而在其他的頁上則直接用當前ip對比數據庫中的ip,代碼如下!

  限制ip添加頁html代碼

<%@ 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>無標題頁</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" >
            <tr>
                <td rowspan="2" >
                    <asp:listbox id="iplxb" runat="server" datasourceid="sqldatasource1" datatextfield="ip"
                        datavaluefield="ip" height="194px" width="153px"></asp:listbox></td>
                <td >
                    填寫標準的ip地址到左下文本框里面,然后點擊按紐添加!<br />
                    <asp:regularexpressionvalidator id="regularexpressionvalidator1" runat="server" controltovalidate="iptb"
                        display="dynamic" errormessage="ip地址格式不正確" validationexpression="([0-9]{2,3})([.])([0-9]{1,3})([.])([0-9]{1,3})([.])([0-9]{1,3})"></asp:regularexpressionvalidator></td>
            </tr>
            <tr>
                <td >
                    <asp:linkbutton id="linkbutton1" runat="server" onclick="linkbutton1_click">刪除選中的行</asp:linkbutton></td>
            </tr>
            <tr>
                <td >
                    <asp:textbox id="iptb" runat="server" width="150px">61.139.33.22</asp:textbox></td>
                <td >
                    <asp:button id="button1" runat="server" onclick="button1_click" text="增加" width="80px" /></td>
            </tr>
      </table>   
    </div>
    </form>
</body>
</html>

  限制ip添加頁cs代碼

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 button1_click(object sender, eventargs e)
    {       
        iplxb.items.add(iptb.text);
        odb.insert("insert into ip (ip) values ('" + iptb.text + "')");
    }
    protected void linkbutton1_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);
            }
        }
    }
}

  被需要限制ip的頁面調用頁的代碼

 protected void page_load(object sender, eventargs e)
    {
        string ip = request.userhostaddress.tostring();
            if (convert.toint32(odb.scr("select count(*) from [ip] where ip='" + ip + "'")) > 0)
            response.write("對不起,您的ip被限制訪問,請咨詢管理員");
    }
}

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 潼关县| 新化县| 阳谷县| 池州市| 青龙| 酒泉市| 教育| 四子王旗| 会同县| 韩城市| 潼关县| 琼海市| 井冈山市| 金坛市| 通道| 五莲县| 本溪| 永安市| 青河县| 汉川市| 鲜城| 双城市| 宣汉县| 平定县| 滨州市| 娄底市| 永川市| 远安县| 洪雅县| 香格里拉县| 富源县| 开鲁县| 四子王旗| 丰原市| 新和县| 昂仁县| 曲阜市| 界首市| 天气| 原阳县| 舒兰市|