• 复习asp.net中页面之间传值【02】Url传值


    当客户端发出请求执行asp.net程序时,CLR会将客户端的请求信息包含在Request对象中。这些请求信息包括请求报头,客户端的基本信息(如浏览器类型,浏览器版本号,用户所用的语言以及编码方式等),请求方法(如post,get),参数名,参数值等。
    Request对象的调用方法:Request.Collection["Variable"];
    其中Collection包括四种集合:QueryString,Form,Cookies,ServerVariables。
    1.QueryString集合收集的信息来源于请求url地址中"?"号后面的数据,这些数据称作url附加信息。例如,www.sina.com/show.asp?id=111
    在此url中,QueryString收集到的信息是"show.asp?"后面的数据"id=111"。此时,取得参数"id"的参数值的语句为:Request.QueryString["id"];
    QueryString主要用于收集http协议中get请求发送的数据,如果在一个请求事件中被请求的程序url地址出现了"?"号后的数据,则表示此次请求方式为get。get方法是http中的默认请求方法。

    get 方法是将传递的数据追加至url中。url地址长度是有限制的,因此使用get方法所能传递的数据也是有限的。一般地,get方法能够传递256字节的数 据,在多数情况下,使用get方法传递的数据长度是远远不够的

    下面默认发出页面Default.aspx     接收页面Get.aspx

    Default.aspx

    using System;
    using System.Collections.Generic;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;

    namespace WebApplication1
    {
    public partial class _Default : System.Web.UI.Page
    {
    protected void Page_Load(object sender, EventArgs e)
    {
    Response.Redirect("~/GetPage.aspx?id=雪夜尘封");
    }
    }
    }

    GetPage.aspx

    using System;
    using System.Collections.Generic;

    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;

    namespace WebApplication1
    {
    public partial class GetPage : System.Web.UI.Page
    {
    protected void Page_Load(object sender, EventArgs e)
    {

    string[] name1= Request.QueryString.GetValues("id");//index System.Web.HttpRequest
    Response.Write("name1"+name1[0]);
    string[] name1int = Request.QueryString.GetValues(0);//index
    Response.Write("name1" + name1int[0]);


    string name2 = Request["id"];//只支持string索引
    Response.Write("name2"+name2);



    string name3=Request.QueryString["id"];
    Response.Write("name3"+name3);
    string name3int = Request.QueryString[0];
    Response.Write("name3" + name3int);
    }
    }
    }

  • 相关阅读:
    disconf 2.6.36 install
    Kubernetes 1.6.1 Kargo
    50个必备的实用jQuery代码段
    jquery封装插件
    java读取txt文件
    file 创建 txt文件
    想要学习web前端的童鞋们 可以看看哦 ! 我认为这几本书超不错
    jquery 杂记
    以文件流的方式 文件上传 下载
    陌生单词记录
  • 原文地址:https://www.cnblogs.com/mxxblog/p/2369171.html
Copyright © 2020-2023  润新知