请参阅以下代码:
Public Class _Default
Inherits Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
Using outputFile As New IO.StreamWriter("c:\log.txt", True)
outputFile.WriteLine("Got here")
End Using
If Request.QueryString("id") = "1" Then
TextBox1.Text = "id1"
ElseIf Request.QueryString("id") = "2" Then
TextBox1.Text = "id2"
End If
End Sub
End Class
以及以下代码:
Public Class Test
Inherits System.Web.UI.Page
Private Sub page_Load(sender As Object, e As EventArgs) Handles form1.Load
SendPageRequest()
End Sub
Private Sub SendPageRequest()
Dim proxy As New Net.WebProxy
Dim webReq As Net.HttpWebRequest = CType(Net.WebRequest.Create("http://localhost:58722/Default.aspx?id=1"), Net.HttpWebRequest)
If proxy IsNot Nothing Then webReq.Proxy = proxy
Using webResp As Net.HttpWebResponse = CType(webReq.GetResponse(), Net.HttpWebResponse)
'Get the response, then close it as we don't actually need anything but to send the request.
End Using
End Sub
End Class
和下面的代码(default.aspx):
<%@ Page Title="Home Page" Language="VB" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="Default.aspx.vb" Inherits="Caching._Default" %>
<%@ OutputCache Duration="60" VaryByParam="None" %>
<asp:Content ID="MainContent" ContentPlaceHolderID="MainContent" runat="server">
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
</asp:Content>
我首先导航到:test.aspx,然后导航到default.aspx。
当我访问它时(访问test.aspx之后),我没有将任何查询字符串参数传递给default.aspx。但是,文本框为空,表示我访问test.aspx时未设置缓存。这是为什么?