现在的位置: 首页 > 综合 > 正文

Request实例导学

2012年02月18日 ⁄ 综合 ⁄ 共 1122字 ⁄ 字号 评论关闭

等价方法

Request.QueryString["b"]等价于Request["b"]

if (this.Request.QueryString["b"] == null)

 

1.放两个textBox一个Button
  ID分别为:name,age,Button1
  添加单击事件如下:
    protected void Button1_Click(object sender, EventArgs e)
    {
        //使用Post方式传递数据.
        string name = Request.Form["name"];//取得表单中ID是name的控件的值.
        string age = Request.Form["age"];
        Response.Write("你的姓名是:" + name + "<br>" + "你的年龄是:" + age + "<br>");
        Response.Write("你使用的是" + Request.RequestType + "方式传送数据");
    }

2.用Request获取服务器信息.服务器环境变量.
  为按钮添加事件响应如下:
   Response.Write("当前网页虚拟路径是:" + Request.ServerVariables["url"]);
        Response.Write("<br>实际路径:" + Request.ServerVariables["path_translated"]);
        Response.Write("<br>服务器名:" + Request.ServerVariables["server_name"]);
        Response.Write("<br>服务器IP:" + Request.UserHostAddress);
        //另一种方面
        Response.Write("<br>当前网页虚拟路径是:" + Request.RawUrl);
        Response.Write("<br>实际路径:" + Request.PhysicalPath);

 
3.用Request获取用户信息.浏览器环境变量.
  为按钮添加事件响应如下:
   Response.Write("<br>这个浏览器是否支持背景音乐:" + Request.Browser.BackgroundSounds);
        Response.Write("<br>这个浏览器是否支持框架:" + Request.Browser.Frames);
        Response.Write("<br>客户用的是什么系统:" + Request.Browser.Platform); 

抱歉!评论已关闭.