Posts Tagged ‘asp.net’

Asp.Net中读取QQWry.Dat进行IP查询的方法

十二月 16th, 2006

如何用QQ数据库(QQWry.Dat)制作在线IP查询功能

[开发环境]VS.Net 2003
[编程语言]VB.Net

1.为什么要使用QQWry.Dat做为数据源来开发IP查询功能?
由于QQWry.Dat数据准确,且时常更新,较为方便。

2.如何读取QQWry.Dat中的数据?
以Asp.Net为例,详细介绍步骤:
a.新建一个web项目。
b.将QQWry.Dat保存到database目录下(可自己更改别的目录)
在Google中查找最新的QQWry.Dat
c.将IPLocation.dll下载保存到Bin目录下。如下图:
点击下载IPLocation.dll

d.在项目中添加引用,引用IPLocation.dll。
e.在程序代码前添加一行:

Imports IPLocation.IPLocation

f.调用函数IPLocate进行IP查询。

IPLocate(Byval StrConn as string,Byval StrIp as string)
'StrConn 为数据库连接字符串,如:Server.MapPath("database/QQWry.Dat")
'StrIP      为查询IP

完整例子下载:SkyDrive存储

Asp.Net中对Cookie的基本操作

十二月 15th, 2006

语言:vb

Imports System.Web.HttpContext
Public Class CookieFramework
    '写入单个Cookie
    Public Shared Function WriteCookie(ByVal CookieName As String, ByVal CookieValue As String, ByVal ExpiresDate As Integer) As Boolean
        Dim aCookie As New HttpCookie(CookieName)
        aCookie.Value = CookieValue
        aCookie.Expires = DateTime.Now.AddDays(ExpiresDate)
        System.Web.HttpContext.Current.Response.Cookies.Add(aCookie)
    End Function

    '给Cookie集合添加子项
    Public Shared Function WriteCookies(ByVal CookieName As String, ByVal CookieItem As String, ByVal ItemValue As String, ByVal ExpiresDate As Integer) As Boolean
        Dim aCookie As HttpCookie
        If Current.Request.Cookies(CookieName) Is Nothing Then
            aCookie = New HttpCookie(CookieName)
        Else
            aCookie = Current.Request.Cookies(CookieName)
        End If
        aCookie.Values(CookieItem) = ItemValue
        aCookie.Expires = DateTime.Now.AddDays(ExpiresDate)
        System.Web.HttpContext.Current.Response.Cookies.Add(aCookie)
    End Function
    '读取单个Cookie
    Public Shared Function ReadCookie(ByVal CookieName As String) As String
        If Current.Request.Cookies(CookieName) Is Nothing Then
            Return Nothing
        Else
            Return Current.Request.Cookies(CookieName).Value
        End If
    End Function

    '读取Cookie集合中的子项内容
    Public Shared Function ReadCookies(ByVal CookieName As String, ByVal CookieItem As String) As String
        If Current.Request.Cookies(CookieName) Is Nothing Then
            Return Nothing
        Else
            If Current.Request.Cookies(CookieName).Values(CookieItem) Is Nothing Then
                Return Nothing
            Else
                Return Current.Request.Cookies(CookieName).Values(CookieItem)
            End If
        End If
    End Function
    '删除整个Cookie
    Public Shared Function DeleteCookie(ByVal CookieName As String) As Boolean
        Dim aCookie As New HttpCookie(CookieName)
        Dim i As Integer
        Dim limit As Integer = Current.Request.Cookies.Count - 1
        For i = 0 To limit
            aCookie = Current.Request.Cookies(i)
            aCookie.Expires = DateTime.Now.AddDays(-1)
            Current.Response.Cookies.Add(aCookie)
        Next
    End Function
    '删除Cookie集合中的子项
    Public Shared Function DeleteCookies(ByVal CookieName As String, ByVal ItemName As String) As Boolean
        Dim aCookie As HttpCookie = Current.Request.Cookies(CookieName)
        aCookie.Values.Remove(ItemName)
        aCookie.Expires = DateTime.Now.AddDays(1)
        Current.Response.Cookies.Add(aCookie)
    End Function
End Class