比较Redirect、Execute、Transfer

本文通过四个ASP.NET页面示例,展示了使用Redirect、Execute及Transfer方法进行变量传递的区别。redirect.aspx仅实现页面跳转,transfer.aspx传递变量但不返回,而execute.aspx既传递变量又返回。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

代码分4个页面:
show.aspx这里为接收下面三个页面传递变量用的。
redirect.aspx
execute.aspx
transfer.aspx
这三个分别用相应方法进行传递。

代码如下:
redirect.aspx:
<%--测试redirect、execute、transfer三个方法对变量的传递--%>

<%@ Page Language="VB" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">
Sub page_load(ByVal sender As ObjectByVal e As EventArgs)
Dim cook As String
cook 
= "Redirect传递的小甜饼"
Response.Cookies(
"cook").Value = cook
Response.Redirect(
"show.aspx")
End Sub


</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>edirect页面</title>
</head>
<body>
<form id="edirect页面" runat="server">
<div>
Redirect页面
</div>
</form>
</body>
</html>

Execute.aspx:
<%--测试redirect、execute、transfer三个方法对变量的传递--%>

<%@ Page Language="VB" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">
Sub page_load(ByVal sender As ObjectByVal e As EventArgs)
Dim cook As String
cook 
= "Execute传递的小甜饼"
Response.Cookies(
"cook").Value = cook
Server.Execute(
"show.aspx")
End Sub

</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Execute页面</title>
</head>
<body>
<form id="Execute页面" runat="server">
<div>
Execute页面
</div>
</form>
</body>
</html>

Transfer.aspx:
<%--测试redirect、execute、transfer三个方法对变量的传递--%>

<%@ Page Language="VB" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">
Sub page_load(ByVal sender As ObjectByVal e As EventArgs)
Dim cook As String
cook 
= "Transfer传递的小甜饼"
Response.Cookies(
"cook").Value = cook
Server.Transfer(
"show.aspx")
End Sub

</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Transfer页面</title>
</head>
<body>
<form id="Transfer页面" runat="server">
<div>
Transfer页面
</div>
</form>
</body>
</html>

show.aspx:
<%--测试redirect、execute、transfer三个方法对变量的传递--%>

<%@ Page Language="VB" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">
Sub page_load(ByVal sender As ObjectByVal e As EventArgs)
message.text 
= Response.Cookies("cook").Value
End Sub

</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>show页面</title>
</head>
<body>
<form id="show页面" runat="server">
<asp:label ID ="message" runat="server" />
</form>
</body>
</html>

大家调试一下看结果。
Execute.aspx调用时,会传递COOKIC并显示自己HTML内的代码,因为他传递变量并且执行后返回。
redirect.aspx调用时,什么也不显示,因为他不传递变量,也不返回。
transfer.aspx调用时,只传递变量不返回。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值