将参数传递到asp.net中的新页面(在重定向中)
我想用记录填充Asp.net中的Listview,这些记录应该链接到另一个页面。所以,当用户单击一条记录时,他们将重定向到与该记录相关的新页面将参数传递到asp.net中的新页面(在重定向中),asp.net,parameter-passing,url-redirection,request.querystring,Asp.net,Parameter Passing,Url Redirection,Request.querystring,我想用记录填充Asp.net中的Listview,这些记录应该链接到另一个页面。所以,当用户单击一条记录时,他们将重定向到与该记录相关的新页面 在页面重定向中,除了使用“查询字符串””之外,是否还有其他方法传递参数 您可以使用Cookies HttpCookie cookieName = new HttpCookie("Name"); cookieName.Value = "SarahN"; string name = Request.Cookies["Name"].Value; Appl
在页面重定向中,除了使用“
查询字符串”
”之外,是否还有其他方法传递参数 您可以使用Cookies
HttpCookie cookieName = new HttpCookie("Name");
cookieName.Value = "SarahN";
string name = Request.Cookies["Name"].Value;
Application["Name"] = "SarahN";
string Name = Application["Name"].ToString();
TextBox1.Text = this.Context.Items["Parameter"].ToString();
this.Context.Items["Parameter"] = TextBox1.Text;
Server.Transfer("MyForm2.aspx", true);
设置:
HttpCookie cookieName = new HttpCookie("Name");
cookieName.Value = "SarahN";
string name = Request.Cookies["Name"].Value;
Application["Name"] = "SarahN";
string Name = Application["Name"].ToString();
TextBox1.Text = this.Context.Items["Parameter"].ToString();
this.Context.Items["Parameter"] = TextBox1.Text;
Server.Transfer("MyForm2.aspx", true);
获取:
HttpCookie cookieName = new HttpCookie("Name");
cookieName.Value = "SarahN";
string name = Request.Cookies["Name"].Value;
Application["Name"] = "SarahN";
string Name = Application["Name"].ToString();
TextBox1.Text = this.Context.Items["Parameter"].ToString();
this.Context.Items["Parameter"] = TextBox1.Text;
Server.Transfer("MyForm2.aspx", true);
或您可以使用
应用程序变量
HttpCookie cookieName = new HttpCookie("Name");
cookieName.Value = "SarahN";
string name = Request.Cookies["Name"].Value;
Application["Name"] = "SarahN";
string Name = Application["Name"].ToString();
TextBox1.Text = this.Context.Items["Parameter"].ToString();
this.Context.Items["Parameter"] = TextBox1.Text;
Server.Transfer("MyForm2.aspx", true);
设置:
HttpCookie cookieName = new HttpCookie("Name");
cookieName.Value = "SarahN";
string name = Request.Cookies["Name"].Value;
Application["Name"] = "SarahN";
string Name = Application["Name"].ToString();
TextBox1.Text = this.Context.Items["Parameter"].ToString();
this.Context.Items["Parameter"] = TextBox1.Text;
Server.Transfer("MyForm2.aspx", true);
获取:
HttpCookie cookieName = new HttpCookie("Name");
cookieName.Value = "SarahN";
string name = Request.Cookies["Name"].Value;
Application["Name"] = "SarahN";
string Name = Application["Name"].ToString();
TextBox1.Text = this.Context.Items["Parameter"].ToString();
this.Context.Items["Parameter"] = TextBox1.Text;
Server.Transfer("MyForm2.aspx", true);
或您可以使用上下文
对象
通过上下文对象传递值是另一种广泛使用的方法
MyForm1.aspx.cs
HttpCookie cookieName = new HttpCookie("Name");
cookieName.Value = "SarahN";
string name = Request.Cookies["Name"].Value;
Application["Name"] = "SarahN";
string Name = Application["Name"].ToString();
TextBox1.Text = this.Context.Items["Parameter"].ToString();
this.Context.Items["Parameter"] = TextBox1.Text;
Server.Transfer("MyForm2.aspx", true);
MyForm2.aspx.cs
HttpCookie cookieName = new HttpCookie("Name");
cookieName.Value = "SarahN";
string name = Request.Cookies["Name"].Value;
Application["Name"] = "SarahN";
string Name = Application["Name"].ToString();
TextBox1.Text = this.Context.Items["Parameter"].ToString();
this.Context.Items["Parameter"] = TextBox1.Text;
Server.Transfer("MyForm2.aspx", true);
从
上下文
上下文对象保存单个用户的数据
请求,并且它仅在请求期间保持。这个
上下文容器可以保存大量数据,但通常是这样
用于保存小块数据,因为它通常是为
每个请求都通过global.asax中的处理程序执行。上下文
容器(可从页面对象访问或使用
提供System.Web.HttpContext.Current)来保存需要的值
在不同的HttpModule和HttpHandler之间传递。它可以
也可用于保存与整个系统相关的信息
要求例如,IBuySpy门户填充一些配置
在应用程序\u BeginRequest期间将信息放入此容器
global.asax中的事件处理程序。请注意,这仅适用于以下情况:
当前请求;如果你需要一些仍然存在的东西
对于下一个请求,请考虑使用VIEWSTATE。设置和获取
上下文集合中的数据使用与您所使用的语法相同的语法
已经看到了与其他集合对象(如应用程序)的关系,
会话和缓存。此处显示了两个简单示例:
你也可以参考:
QueryString
有什么具体原因吗?变量太多了,也因为它们都是数字,加密时没有任何变化,所以不安全