首页 优化推广 ASP.NET2.0 c# 获取浏览器,IP,URL,操作系统

ASP.NET2.0 c# 获取浏览器,IP,URL,操作系统

来源: | 时间:2010/7/20 15:03:37 |

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.Net;
using System.Text;
using System.IO;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        //
获取URL地址

        string url = Request.Url.ToString();
        txtUrl.Text = url;
        //
获取IP地址
        string ips= Request.UserHostAddress.ToString();
        txtIp.Text = ips;
        //
浏览器
        string fr = Request.Browser.Type.ToString();
      // txtbrows.Text = fr;
        string cp ;//= Request.UserAgent.ToString()
        cp=GetOSNameByUserAgent(Request.UserAgent.ToString());
        txtcp.Text = cp;
        //
浏览器
        this.txtbrows.Text = Request.Browser.ClrVersion.ToString();
      // txtUrl.Text = Request.ServerVariables["http_referer"];
    }

    protected void btnGet_Click(object sender, EventArgs e)
    {
        txtUrl.Text = Request.ServerVariables["http_referer"];//ServerViables["http_referer"];
        string strurl= txtUrl.Text.ToString(); //
欲获取的网页地址   http://
        WebClient myWebClient = new WebClient(); //
创建WebClient实例
myWebClient

        //
获取或设置用于对向 Internet 资源的请求进行身份验证的网络凭据。

        myWebClient.Credentials = CredentialCache.DefaultCredentials;
      // Request.ServerVariables("HTTP_HOST");
        //
从资源下载数据并返回字节数组。(加@是因为网址中间有"/"符号)
        byte[] pagedata = myWebClient.DownloadData(@strurl);
     
      string result = Encoding.Default.GetString(pagedata); //
如果获取网站页面采用的是GB2312,则使用这句
        //string result = Encoding.UTF8.GetString(pagedata); //
如果获取网站页面采用的是UTF-8,则使用这句
        Response.Write(result); //
WEB页中显示获取的内容
        Panel1.Visible = false;

服务热线

153 8323 9821

功能和特性

价格和优惠

网站和维护

推广和优化

微信服务号