using System;
using System.Data;
using System.Configuration;
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;
using System.Collections;
using System.Collections.Generic;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
///<summary>
///在asp.net中获得客户端的一些信息
///base on:http://www.cnblogs.com/anjou/archive/2008/08/04/1259843.html (大豆男生)
///</summary>
Dictionary<string,string> clientInfos = new Dictionary<string,string>();
//ArrayList clientInfos = new ArrayList();
try
{
string ip = Request.UserHostAddress;
string userAgent = Request.UserAgent == null ? "no" : Request.UserAgent;
if(Request.ServerVariables["HTTP_UA_CPU"] == null){
clientInfos.Add("CPU 类型","未知");
}else{
clientInfos.Add("CPU 类型",Request.ServerVariables["HTTP_UA_CPU"]);
}
clientInfos.Add("操作系统",this.GetOSNameByUserAgent(userAgent));
clientInfos.Add("IP地址",ip);
//利用CLR获取对方浏览器版本
if(Request.Browser.ClrVersion == null)
clientInfos.Add(".net clr version","not support");
else
clientInfos.Add(".net clr vsrsion",Request.Browser.ClrVersion.ToString());
clientInfos.Add("Browser",Request.Browser.Browser+Request.Browser.Version);
//是否支持Activex、Cookies以及使用的语言
clientInfos.Add("support Activex",Request.Browser.ActiveXControls ? "support":"not support");
clientInfos.Add("support cookies",Request.Browser.Cookies ? "支持" : "不支持");
clientInfos.Add("lang",Request.UserLanguages[0]);
//使用的登录设备
string httpAccept = Request.ServerVariables["HTTP_ACCEPT"];
if(httpAccept == null)
clientInfos.Add("computer/mobilephone","unknown");
else if(httpAccept.IndexOf("wap") > -1)
clientInfos.Add("computer/mobilephone","mobilephone");
else
clientInfos.Add("computer/mobilephone","computer");
clientInfos.Add("platform",Request.Browser.Platform);
clientInfos.Add("win16",Request.Browser.Win16 ? "yes" : "no");
clientInfos.Add("win32",Request.Browser.Win32 ? "yes" : "no");
//编码方式
if(Request.ServerVariables["HTTP_ACCEPT_ENCODING"] == null)
clientInfos.Add("Http Accept Encoding","nothing");
else
clientInfos.Add("Http Accept Encoding",Request.ServerVariables["HTTP_ACCEPT_ENCODING"]);
clientInfos.Add("User Agent",userAgent);
}
catch(Exception ex)
{
Response.Write(ex);
}
//显示所获得的信息
this.Response.Write("<table cellpadding=0 cellspacing=0>");
this.Response.Write("<tr>");
this.Response.Write("<td width=145px>item</td>");
this.Response.Write("<td>value</td>");
this.Response.Write("</tr>");
foreach(string key in clientInfos.Keys){
this.Response.Write("<tr>");
this.Response.Write("<td>" + key + "</td>");
this.Response.Write("<td>" + clientInfos[key].ToString() + "</td>");
this.Response.Write("</tr>");
}
this.Response.Write("</table>");
}
/// <summary>
/// 根据 User Agent 获取操作系统名称
/// </summary>
private string GetOSNameByUserAgent(string userAgent)
{
string osVersion = "未知";
if (userAgent.Contains("NT 6.0"))
{
osVersion = "Windows Vista/Server 2008";
}
else if (userAgent.Contains("NT 5.2"))
{
osVersion = "Windows Server 2003";
}
else if (userAgent.Contains("NT 5.1"))
{
osVersion = "Windows XP";
}
else if (userAgent.Contains("NT 5"))
{
osVersion = "Windows 2000";
}
else if (userAgent.Contains("NT 4"))
{
osVersion = "Windows NT4";
}
else if (userAgent.Contains("Me"))
{
osVersion = "Windows Me";
}
else if (userAgent.Contains("98"))
{
osVersion = "Windows 98";
}
else if (userAgent.Contains("95"))
{
osVersion = "Windows 95";
}
else if (userAgent.Contains("Mac"))
{
osVersion = "Mac";
}
else if (userAgent.Contains("Unix"))
{
osVersion = "UNIX";
}
else if (userAgent.Contains("Linux"))
{
osVersion = "Linux";
}
else if (userAgent.Contains("SunOS"))
{
osVersion = "SunOS";
}
return osVersion;
}
/// <summary>
/// “上传”文件按钮单击事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Button1_ServerClick(object sender, EventArgs e)
{
//获取文件名
ArrayList arrFileName = new ArrayList();
Page.Response.Write("<b>" + arrFileName.Count + "</b>");
Page.Response.Write("<b>" + File1.Value + "</b>");
arrFileName.AddRange(File1.Value.Split('\\'));
Page.Response.Write("<i>" + arrFileName.Count + "</i>");
string fileName = arrFileName[arrFileName.Count - 1].ToString();
//查看arrFileName数组的内容
for (int i = 0; i < arrFileName.Count; i++) {
Page.Response.Write("<hr />");
Page.Response.Write(arrFileName[i].ToString());
}
//获取文件所要保存的路径
String savePath = "E:\\uploads\\";
//上传文件
File1.PostedFile.SaveAs(savePath + fileName);
Page.Response.Write("文件上传成功!");
}
}
using System.Data;
using System.Configuration;
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;
using System.Collections;
using System.Collections.Generic;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
///<summary>
///在asp.net中获得客户端的一些信息
///base on:http://www.cnblogs.com/anjou/archive/2008/08/04/1259843.html (大豆男生)
///</summary>
Dictionary<string,string> clientInfos = new Dictionary<string,string>();
//ArrayList clientInfos = new ArrayList();
try
{
string ip = Request.UserHostAddress;
string userAgent = Request.UserAgent == null ? "no" : Request.UserAgent;
if(Request.ServerVariables["HTTP_UA_CPU"] == null){
clientInfos.Add("CPU 类型","未知");
}else{
clientInfos.Add("CPU 类型",Request.ServerVariables["HTTP_UA_CPU"]);
}
clientInfos.Add("操作系统",this.GetOSNameByUserAgent(userAgent));
clientInfos.Add("IP地址",ip);
//利用CLR获取对方浏览器版本
if(Request.Browser.ClrVersion == null)
clientInfos.Add(".net clr version","not support");
else
clientInfos.Add(".net clr vsrsion",Request.Browser.ClrVersion.ToString());
clientInfos.Add("Browser",Request.Browser.Browser+Request.Browser.Version);
//是否支持Activex、Cookies以及使用的语言
clientInfos.Add("support Activex",Request.Browser.ActiveXControls ? "support":"not support");
clientInfos.Add("support cookies",Request.Browser.Cookies ? "支持" : "不支持");
clientInfos.Add("lang",Request.UserLanguages[0]);
//使用的登录设备
string httpAccept = Request.ServerVariables["HTTP_ACCEPT"];
if(httpAccept == null)
clientInfos.Add("computer/mobilephone","unknown");
else if(httpAccept.IndexOf("wap") > -1)
clientInfos.Add("computer/mobilephone","mobilephone");
else
clientInfos.Add("computer/mobilephone","computer");
clientInfos.Add("platform",Request.Browser.Platform);
clientInfos.Add("win16",Request.Browser.Win16 ? "yes" : "no");
clientInfos.Add("win32",Request.Browser.Win32 ? "yes" : "no");
//编码方式
if(Request.ServerVariables["HTTP_ACCEPT_ENCODING"] == null)
clientInfos.Add("Http Accept Encoding","nothing");
else
clientInfos.Add("Http Accept Encoding",Request.ServerVariables["HTTP_ACCEPT_ENCODING"]);
clientInfos.Add("User Agent",userAgent);
}
catch(Exception ex)
{
Response.Write(ex);
}
//显示所获得的信息
this.Response.Write("<table cellpadding=0 cellspacing=0>");
this.Response.Write("<tr>");
this.Response.Write("<td width=145px>item</td>");
this.Response.Write("<td>value</td>");
this.Response.Write("</tr>");
foreach(string key in clientInfos.Keys){
this.Response.Write("<tr>");
this.Response.Write("<td>" + key + "</td>");
this.Response.Write("<td>" + clientInfos[key].ToString() + "</td>");
this.Response.Write("</tr>");
}
this.Response.Write("</table>");
}
/// <summary>
/// 根据 User Agent 获取操作系统名称
/// </summary>
private string GetOSNameByUserAgent(string userAgent)
{
string osVersion = "未知";
if (userAgent.Contains("NT 6.0"))
{
osVersion = "Windows Vista/Server 2008";
}
else if (userAgent.Contains("NT 5.2"))
{
osVersion = "Windows Server 2003";
}
else if (userAgent.Contains("NT 5.1"))
{
osVersion = "Windows XP";
}
else if (userAgent.Contains("NT 5"))
{
osVersion = "Windows 2000";
}
else if (userAgent.Contains("NT 4"))
{
osVersion = "Windows NT4";
}
else if (userAgent.Contains("Me"))
{
osVersion = "Windows Me";
}
else if (userAgent.Contains("98"))
{
osVersion = "Windows 98";
}
else if (userAgent.Contains("95"))
{
osVersion = "Windows 95";
}
else if (userAgent.Contains("Mac"))
{
osVersion = "Mac";
}
else if (userAgent.Contains("Unix"))
{
osVersion = "UNIX";
}
else if (userAgent.Contains("Linux"))
{
osVersion = "Linux";
}
else if (userAgent.Contains("SunOS"))
{
osVersion = "SunOS";
}
return osVersion;
}
/// <summary>
/// “上传”文件按钮单击事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Button1_ServerClick(object sender, EventArgs e)
{
//获取文件名
ArrayList arrFileName = new ArrayList();
Page.Response.Write("<b>" + arrFileName.Count + "</b>");
Page.Response.Write("<b>" + File1.Value + "</b>");
arrFileName.AddRange(File1.Value.Split('\\'));
Page.Response.Write("<i>" + arrFileName.Count + "</i>");
string fileName = arrFileName[arrFileName.Count - 1].ToString();
//查看arrFileName数组的内容
for (int i = 0; i < arrFileName.Count; i++) {
Page.Response.Write("<hr />");
Page.Response.Write(arrFileName[i].ToString());
}
//获取文件所要保存的路径
String savePath = "E:\\uploads\\";
//上传文件
File1.PostedFile.SaveAs(savePath + fileName);
Page.Response.Write("文件上传成功!");
}
}