获取浏览器信息

获取浏览器信息:

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        Dim bc As HttpBrowserCapabilities = Request.Browser()
        Response.Write("类型:" & bc.Type & "<br>")
        Response.Write("名称:" & bc.Browser & "<br>")
        Response.Write("版本:" & bc.Version & "<br>")
        Response.Write("操作系统平台:" & bc.Platform & "<br>")
        Response.Write("是否测试版:" & bc.Beta & "<br>")
        Response.Write("是否支持框架:" & bc.Frames & "<br>")
        Response.Write("是否支持表格:" & bc.Tables & "<br>")
        Response.Write("是否支持VBScript:" & bc.VBScript & "<br>")
        Response.Write("是否支持JavaScript:" & bc.JavaScript & "<br>")
        Response.Write("是否支持JavaApplets:" & bc.JavaApplets & "<br>")
        Response.Write("是否支持ActiveX插件:" & bc.ActiveXControls & "<br>")
    End Sub
*************************************************
获取服务器信息
    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        Response.Write("本地IP:" & Request.ServerVariables.Item("local_addr") & "<br>")
        Response.Write("当前被请求的相对路径:" & Request.ServerVariables.Item("path_info") & "<br>")
        Response.Write("被请求的绝对路径:" & Request.ServerVariables.Item("path_translated") & "<br>")
        Response.Write("服务器名称:" & Request.ServerVariables.Item("server_name") & "<br>")
        Response.Write("服务器端口号:" & Request.ServerVariables.Item("server_port") & "<br>")
        Response.Write("响应服务器程序:" & Request.ServerVariables.Item("server_software") & "<br>")
    End Sub
*******************************************************
获取根目录:
        Response.Write("<b>获取绝对路径</b><br><br>")
        Response.Write("当前绝对路径:" & Server.MapPath("."))
**********************************
连html标记一起显示:
Response.Write("可以看到html标记:" & Server.HtmlEncode("<h1>你好!</h1>"))
************************************
制作留言本


Imports System.Data
Imports System.Data.OleDb
Public Class WebForm3
    Inherits System.Web.UI.Page


#Region " Web 窗体设计器生成的代码 "

    '该调用是 Web 窗体设计器所必需的。
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.OleDbDataAdapter1 = New System.Data.OleDb.OleDbDataAdapter
        Me.OleDbSelectCommand1 = New System.Data.OleDb.OleDbCommand
        Me.OleDbInsertCommand1 = New System.Data.OleDb.OleDbCommand
        Me.OleDbConnection1 = New System.Data.OleDb.OleDbConnection
        Me.DataSet11 = New example.DataSet1
        CType(Me.DataSet11, System.ComponentModel.ISupportInitialize).BeginInit()
        '
        'OleDbDataAdapter1
        '
        Me.OleDbDataAdapter1.InsertCommand = Me.OleDbInsertCommand1
        Me.OleDbDataAdapter1.SelectCommand = Me.OleDbSelectCommand1
        Me.OleDbDataAdapter1.TableMappings.AddRange(New System.Data.Common.DataTableMapping() {New System.Data.Common.DataTableMapping("Table", "liuyan", New System.Data.Common.DataColumnMapping() {New System.Data.Common.DataColumnMapping("留言", "留言"), New System.Data.Common.DataColumnMapping("时间", "时间"), New System.Data.Common.DataColumnMapping("姓名", "姓名")})})
        '
        'OleDbSelectCommand1
        '
        Me.OleDbSelectCommand1.CommandText = "SELECT 留言, 时间, 姓名 FROM liuyan"
        Me.OleDbSelectCommand1.Connection = Me.OleDbConnection1
        '
        'OleDbInsertCommand1
        '
        Me.OleDbInsertCommand1.CommandText = "INSERT INTO liuyan(留言, 时间, 姓名) VALUES (?, ?, ?)"
        Me.OleDbInsertCommand1.Connection = Me.OleDbConnection1
        Me.OleDbInsertCommand1.Parameters.Add(New System.Data.OleDb.OleDbParameter("留言", System.Data.OleDb.OleDbType.VarWChar, 0, "留言"))
        Me.OleDbInsertCommand1.Parameters.Add(New System.Data.OleDb.OleDbParameter("时间", System.Data.OleDb.OleDbType.DBDate, 0, "时间"))
        Me.OleDbInsertCommand1.Parameters.Add(New System.Data.OleDb.OleDbParameter("姓名", System.Data.OleDb.OleDbType.VarWChar, 12, "姓名"))
        '
        'OleDbConnection1
        '
        Me.OleDbConnection1.ConnectionString = "Jet OLEDB:Global Partial Bulk Ops=2;Jet OLEDB:Registry Path=;Jet OLEDB:Database L" & _
        "ocking Mode=1;Data Source=""E:/Inetpub/wwwroot/liuyan.mdb"";Jet OLEDB:Engine Type=" & _
        "5;Provider=""Microsoft.Jet.OLEDB.4.0"";Jet OLEDB:System database=;Jet OLEDB:SFP=Fa" & _
        "lse;persist security info=False;Extended Properties=;Mode=Share Deny None;Jet OL" & _
        "EDB:Encrypt Database=False;Jet OLEDB:Create System Database=False;Jet OLEDB:Don'" & _
        "t Copy Locale on Compact=False;Jet OLEDB:Compact Without Replica Repair=False;Us" & _
        "er ID=Admin;Jet OLEDB:Global Bulk Transactions=1"
        '
        'DataSet11
        '
        Me.DataSet11.DataSetName = "DataSet1"
        Me.DataSet11.Locale = New System.Globalization.CultureInfo("zh-CN")
        CType(Me.DataSet11, System.ComponentModel.ISupportInitialize).EndInit()

    End Sub
    Protected WithEvents Label1 As System.Web.UI.WebControls.Label
    Protected WithEvents DataGrid1 As System.Web.UI.WebControls.DataGrid
    Protected WithEvents Label2 As System.Web.UI.WebControls.Label
    Protected WithEvents Label3 As System.Web.UI.WebControls.Label
    Protected WithEvents Label4 As System.Web.UI.WebControls.Label
    Protected WithEvents TextBox1 As System.Web.UI.WebControls.TextBox
    Protected WithEvents TextBox2 As System.Web.UI.WebControls.TextBox
    Protected WithEvents Button1 As System.Web.UI.WebControls.Button
    Protected WithEvents Button2 As System.Web.UI.WebControls.Button
    Protected WithEvents OleDbDataAdapter1 As System.Data.OleDb.OleDbDataAdapter
    Protected WithEvents OleDbSelectCommand1 As System.Data.OleDb.OleDbCommand
    Protected WithEvents OleDbInsertCommand1 As System.Data.OleDb.OleDbCommand
    Protected WithEvents OleDbConnection1 As System.Data.OleDb.OleDbConnection
    Protected WithEvents DataSet11 As example.DataSet1

    '注意: 以下占位符声明是 Web 窗体设计器所必需的。
    '不要删除或移动它。
    Private designerPlaceholderDeclaration As System.Object

    Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
        'CODEGEN: 此方法调用是 Web 窗体设计器所必需的
        '不要使用代码编辑器修改它。
        InitializeComponent()
    End Sub

#End Region

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        If Not IsPostBack Then
            Dim mycon As New OleDbConnection
            Dim myadpt As New OleDbDataAdapter
            Dim myds As New DataSet
            mycon.ConnectionString = "provider=microsoft.jet.oledb.4.0;source=" & Server.MapPath("liuyan.mdb")
            myadpt.SelectCommand = New OleDbCommand
            myadpt.SelectCommand.CommandText = "select * from liuyan"
            myadpt.SelectCommand.Connection = mycon
            myadpt.Fill(myds, "1")
            datagrid1.datasource = myds.Tables("1").DefaultView
            datagrid1.databind()
            mycon.Close()
        End If
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        If TextBox1.Text = "" Or TextBox2.Text = "" Then
            Label2.Text = "请输入完整的数据后再提交!"
        Else
            Dim mycon As New OleDbConnection
            Dim mycmd As New OleDbCommand
            mycon.ConnectionString = "provider=microsoft.jet.oledb.4.0;source=" & Server.MapPath("liuyan.mdb")
            mycon.Open()
            mycmd.Connection = mycon
            mycmd.CommandText = "insert into liuyan values('" & TextBox1.Text & "','" & TextBox2.Text & "','" & Now & "')"
            mycmd.ExecuteNonQuery()
            Dim myadpt As New OleDbDataAdapter
            Dim myds As New DataSet
            myadpt.SelectCommand.CommandText = "select * from liuyan"
            myadpt.SelectCommand.Connection = mycon
            myadpt.Fill(myds, "1")
            DataGrid1.DataSource = myds.Tables("1").DefaultView
            DataGrid1.DataBind()
            mycon.Close()
        End If
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        TextBox1.Text = ""
        TextBox2.Text = ""
    End Sub
End Class

****************************************************************************
在ASP.NET 中实现单点登录
出自:【孟宪会之精彩世界】 发布日期:2005年1月27日 8点48分0秒 [有删改]
由于某些原因,在我们的应用中会遇到一个用户只能在一个地方登录的情况,也就是我们通常所说的单点登录。在ASP.NET中实现单点登录其实很简单,下面就把主要的方法和全部代码进行分析。

实现思路

利用Cache的功能,我们把用户的登录信息保存在Cache中,并设置过期时间为Session失效的时间,因此,一旦Session失效,我们的Cache也过期;而Cache对所有的用户都可以访问,因此,用它保存用户信息比数据库来得方便。

SingleLogin.aspx代码

<%@ Page language="c#" Codebehind="SingleLogin.aspx.cs" AutoEventWireup="false"
 Inherits="eMeng.Exam.SingleLogin" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>单点登录测试</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<style>
H3 { FONT: 17px 宋体 }
INPUT { FONT: 12px 宋体 }
SPAN { FONT: 12px 宋体 }
P { FONT: 12px 宋体 }
H4 { FONT: 12px 宋体 }
</style>
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
  <div align="center">
    <h3>单点登录测试</h3>
    <p>用户名称:<asp:TextBox id="UserName" runat="server"></asp:TextBox></p>
    <p>用户密码:<asp:TextBox id="PassWord" runat="server" TextMode="Password"></asp:TextBox></p>
    <p><asp:Button id="Login" runat="server" Text=" 登  录 "></asp:Button></p>
    <p><asp:Label id="Msg" runat="server"></asp:Label></p>
  </div>
</form>
</body>
</HTML>

SingleLogin.aspx.cs代码

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

namespace eMeng.Exam
{
/// <summary>
/// SingleLogin 的摘要说明。
/// 实现单点登录
/// </summary>
public class SingleLogin : System.Web.UI.Page
{
protected System.Web.UI.WebControls.TextBox UserName;
protected System.Web.UI.WebControls.TextBox PassWord;
protected System.Web.UI.WebControls.Label Msg;
protected System.Web.UI.WebControls.Button Login;

private void Page_Load(object sender, System.EventArgs e)
{

}

#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
  InitializeComponent();
  base.OnInit(e);
}

/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
  this.Login.Click += new System.EventHandler(this.Login_Click);
  this.Load += new System.EventHandler(this.Page_Load);
}
#endregion

private void Login_Click(object sender, System.EventArgs e)
{
  // 作为唯一标识的Key,应该是唯一的,这可根据需要自己设定规则。
  // 做为测试,这里用用户名和密码的组合来做标识;也不进行其它的错误检查。

  // 生成Key
  string sKey = UserName.Text + "_" + PassWord.Text;
  // 得到Cache中的给定Key的值
  string sUser = Convert.ToString(Cache[sKey]);
  // 检查是否存在
  if (sUser == null || sUser == String.Empty)
  {
    // Cache中没有该Key的项目,表名用户没有登录,或者已经登录超时
    // 注意下面使用的TimeSpan构造函数重载版本的方法,是进行是否登录判断的关键。
    TimeSpan SessTimeOut = new TimeSpan(0,0,System.Web.HttpContext.Current.Session.Timeout,0,0);
    HttpContext.Current.Cache.Insert(sKey,sKey,null,DateTime.MaxValue,SessTimeOut,
      System.Web.Caching.CacheItemPriority.NotRemovable,null);
    Session["User"] = sKey;
    // 首次登录,您可以做您想做的工作了。
    Msg.Text="<h4 style='color:red'>嗨!欢迎您访问<a href='http://www.21asp.net/'>www.21asp.net";
    Msg.Text += "</a>,祝您浏览愉快!:)</h4>";
  }
  else
  {
    // 在 Cache 中发现该用户的记录,表名已经登录过,禁止再次登录
    Msg.Text="<h4 style='color:red'>抱歉,您好像已经登录了呀:-(</h4>";
   return;
  }
}
}
}
*****************************************************************
显示访问者位数
<script language =vb runat =server >
sub page_load(sender as object,e as eventargs)
Application.Lock() '锁定,不许其他用户修改
Application.Set("cnt",Application("cnt")+1) '访问者计数加1
Application.UnLock() '解锁
counter.text="你是第" & Application("cnt") & "wei"
end sub
</script>
<html >

<body >
<asp:Label Runat =server ID ="counter"/>
</body>
</html>

******************************************************
发送文件到浏览器
<html>

  <body MS_POSITIONING="GridLayout">
 
    <script language =vb runat =server >
    sub page_load(sender as object,e as eventargs)
    Response.Charset="GB2312"
    Response.WriteFile("a.txt") '发送的文件a.txt与该页在同一个目录下
    end sub
    </script>
  </body>
</html>
*********************************************************
在指定的时间内显示页面
<HTML>
 <script language="vb" runat="server">
    sub page_load(sender as object,e as eventargs)
    dim nowtime as byte
    nowtime=System.DateTime.Now.Hour
    if nowtime>10 or nowtime<8 then
    Response.Write("现在时间是:"& System.DateTime.Now.ToLongTimeString() & "<br>")
    Response.Write("本页面现在暂时不供访问")
    Response.end()
    end if
    end sub
 </script>
 <body MS_POSITIONING="GridLayout">
  <FONT face="宋体">
 <p>欢迎光临!</p>
 </FONT>
 </body>
</HTML>
*******************************************************
ASP.NET与ACCESS连接

<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.OleDb" %>

<html>

  <body MS_POSITIONING="GridLayout">
 
    <script language =vb runat =server >
    sub page_load(sender as object,e as eventargs)
    if Not IsPostBack then
    dim conn as new OleDbConnection()
    dim cmd as new OleDbCommand()
    dim obreader as OleDbDataReader
    dim i as integer
    conn.ConnectionString="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("视科软件.mdb")
    conn.Open()
    cmd.Connection=conn     '设置 cmd对象的连接属性
    cmd.CommandText="select id,姓名,性别,联系电话 from 员工信息"  '设置cmd对象的SQL命令
    obreader=cmd.ExecuteReader()  '读取并显示数据
    Response.Write("<center>员工联系单</center>")
    Response.Write("<table align=center border=1><tr align=center>")
    for i=0 to obreader.FieldCount-1 
  Response.Write("<td>"& obreader.GetName(i) &"</td>") '显示i对应的字段名getname
    next
    while obreader.Read()
  Response.Write("<tr>")
  for i=0 to obreader.FieldCount-1
   Response.Write("<td>"& obreader.GetValue(i) &"</td>") '显示i对应的字段值
  next
  Response.Write("</tr>")
 end while
 Response.Write("</table>")
 obreader.Close()
 conn.Close()
  end if
    end sub
    </script>
  </body>
</html>
******************************************************
ASP.NET与SQL连接
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<script language =vb runat =server >
sub page_load(sender as object,e as eventargs)
dim conn as new SqlConnection()

conn.ConnectionString="Data Source=CCNIIT-EQD5D71W;initial catalog=StudentDBMS;integrated security=SSPI;persist security info=False;packet size=4096"
conn.Open()

end sub
</script>
或者:
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<script language =vb runat =server >
sub page_load(sender as object,e as eventargs)
dim conn as new SqlConnection()
dim ord as SqlDataReader
dim i as integer

conn.ConnectionString="Data Source=CCNIIT-EQD5D71W;UID=sa;PWD=sa;DATABASE=StudentDBMS"
conn.Open()

dim cmd as new SqlCommand()
cmd.Connection=conn
cmd.CommandText="select * from course"
ord=cmd.ExecuteReader()
Response.Write("<center>课程信息</center>")
Response.Write("<table align=center border=1><tr align=center>")
for i=0 to ord.FieldCount-1
 Response.Write("<td>"& ord.GetName(i) &"</td>")
next
while ord.Read()
 Response.Write("<tr>")
 For i=0 to ord.FieldCount-1
  Response.Write("<td>"& ord.GetValue(i) &"</td>")
 next
 Response.Write("</tr>")
end while
Response.Write("</table>")
ord.Close()
conn.Close()

end sub
</script>

 


VB连接数据
Private Sub Form_Load()
Public Function execsql(ByVal sql As String) As ADODB.Recordset
Dim cnn As New ADODB.connection
Dim rs As New ADODB.Recordset
cnn.Open "Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Initial Catalog=student;Data Source=ZYDMANGO"
rs.Open sql, cnn, 1, 3
ste execsql = rs
End Function
End Sub 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值