HTTP协议演示_基于 HTTP 的 Web Forms 编程2-5

大概浏览一下下面几段代码。注意代码段中黑体的部分。

1)如果我们用.NET创建一个空页面,.aspx文件内容如下:

代码段一:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
        <div>
        </div>
    </form>
</body>
</html>

以上页面没有任何控件。然后用IE查看它的源文件,如下:

代码段二:

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

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>Untitled Page</title>
</head>
<body>
    <form name="form1" method="post" action="Default.aspx" id="form1">
        <div>
            <input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" 
value="/wEPDwUJNzgzNDMwNTMzZGT8XigVHlmkk+BXiblfwYUp8bVAIA==" />
        </div>
        <div>
        </div>
    </form>
</body>
</html>

即便没有任何控件,却在它的源文件中有个隐藏域。

2)如果向这个页面添加一个HTML文本框,.aspx文件内容如下:

代码段三:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
        <div>
            <input id="Text1" type="text" /></div>
    </form>
</body>
</html>

再查看它的源文件,如下:

代码段四:

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

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>Untitled Page</title>
</head>
<body>
    <form name="form1" method="post" action="Default.aspx" id="form1">
        <div>
            <input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" 
value="/wEPDwUJNzgzNDMwNTMzZGT8XigVHlmkk+BXiblfwYUp8bVAIA==" />
        </div>
        <div>
            <input id="Text1" type="text" />
        </div>
    </form>
</body>
</html>

此时,除了隐藏域,就是真正的HTML文本框。

3)如果向这个页面添加一个ASP.NET控件,.aspx文件内容如下:

代码段五:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
        <div>
            <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox></div>
    </form>
</body>
</html>

查看它的源文件,如下:

代码段六:

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

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>Untitled Page</title>
</head>
<body>
    <form name="form1" method="post" action="Default.aspx" id="form1">
    <div>
        <input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" 
value="/wEPDwUJMjgzMDgzOTgzZGRQ4cwjxigvH0cn0g6XWSHkZbN2Lg==" />
    </div>
    <div>
        <input name="TextBox1" type="text" id="TextBox1" /></div>
    <div>
        <input type="hidden" name="__EVENTVALIDATION" id="__EVENTVALIDATION" 
value="/wEWAgKo3JKxDwLs0bLrBrEWYCZVJeodiUUqcdX2kqmQDHGa" /></div>
    </form>
</body>
</html>

此时的源文件,多了一个。两个隐藏域,分别是“__VIEWSTATE”和“__EVENTVALIDATION”,再就是HTML文本框。

4)另外,我们知道ASP.NET程序中,有几个一直存在的对象,Server对象,Response对象,Request对象等等。如果我们调试一下ASP.NET程序,看看ResponseRequest对象都有些什么。

对于Request对象,你可能看到如下一堆信息。

代码段七:

    AcceptTypes: {Dimensions:[1]}

    AnonymousID: null

    ApplicationPath: "/"

    AppRelativeCurrentExecutionFilePath: "~/Default.aspx"

    Browser: {System.Web.Mobile.MobileCapabilities}

    ClientCertificate: {System.Web.HttpClientCertificate}

    ContentEncoding: {System.Text.UTF8Encoding}

    ContentLength: 0

    ContentType: ""

    Cookies: {System.Web.HttpCookieCollection}

    CurrentExecutionFilePath: "/Default.aspx"

    FilePath: "/Default.aspx"

    Files: {System.Web.HttpFileCollection}

    Filter: {System.Web.HttpInputStreamFilterSource}

    Form: {}

    Headers: {Connection=Keep-Alive&Accept=*%2f*&Accept-Encoding=gzip%2c+deflate&Accept-Language=zh-cn&Host=localhost%3a1234&User-Agent=Mozilla%2f4.0+(compatible%3b+MSIE+7.0%3b+Windows+NT+5.2%3b+.NET+CLR+1.1.4322%3b+.NET+CLR+2.0.50727)&UA-CPU=x86}

    HttpMethod: "GET"

    InputStream: {System.Web.HttpInputStream}

    IsAuthenticated: false

    IsLocal: true

    IsSecureConnection: false

    LogonUserIdentity: {System.Security.Principal.WindowsIdentity}

    Params: {ALL_HTTP=HTTP_CONNECTION%3aKeep-Alive%0d%0aHTTP_ACCEPT%3a*%2f*%0d%0aHTTP_ACCEPT_ENCODING%3agzip%2c+deflate%0d%0aHTTP_ACCEPT_LANGUAGE%3azh-cn%0d%0aHTTP_HOST%3alocalhost%3a1234%0d%0aHTTP_USER_AGENT%3aMozilla%2f4.0+(compatible%3b+MSIE+7.0%3b+Windows+NT+5.2%3b+.NET+CLR+1.1.4322%3b+.NET+CLR+2.0.50727)%0d%0aHTTP_UA_CPU%3ax86%0d%0a&ALL_RAW=Connection%3a+Keep-Alive%0d%0aAccept%3a+*%2f*%0d%0aAccept-Encoding%3a+gzip%2c+deflate%0d%0aAccept-Language%3a+zh-cn%0d%0aHost%3a+localhost%3a1234%0d%0aUser-Agent%3a+Mozilla%2f4.0+(compatible%3b+MSIE+7.0%3b+Windows+NT+5.2%3b+.NET+CLR+1.1.4322%3b+.NET+CLR+2.0.50727)%0d%0aUA-CPU%3a+x86%0d%0a&APPL_MD_PATH=%2fLM%2fW3SVC%2f1860662192%2fRoot&APPL_PHYSICAL_PATH=D%3a%5cMyTest%5cWebSite1%5c&AUTH_TYPE=&AUTH_USER=&AUTH_PASSWORD=&LOGON_USER=&REMOTE_USER=&CERT_COOKIE=&CERT_FLAGS=&CERT_ISSUER=&CERT_KEYSIZE=&CERT_SECRETKEYSIZE=&CERT_SERIALNUMBER=&CERT_SERVER_ISSUER=&CERT_SERVER_SUBJECT=&CERT_SUBJECT=&CONTENT_LENGTH=0&CONTENT_TYPE=&GATEWAY_INTERFACE=CGI%2f1.1&HTTPS=off&HTTPS_KEYSIZE=&H

TTPS_SECRETKEYSIZE=&HTTPS_SERVER_ISSUER=&HTTPS_SERVER_SUBJECT=&INSTANCE_ID=1860662192&INSTANCE_META_PATH=%2fLM%2fW3SVC%2f1860662192&LOCAL_ADDR=127.0.0.1&PATH_INFO=%2fDefault.aspx&PATH_TRANSLATED=D%3a%5cMyTest%5cWebSite1%5cDefault.aspx&QUERY_STRING=&REMOTE_ADDR=127.0.0.1&REMOTE_HOST=127.0.0.1&REMOTE_PORT=46201&REQUEST_METHOD=GET&SCRIPT_NAME=%2fDefault.aspx&SERVER_NAME=localhost&SERVER_PORT=1234&SERVER_PORT_SECURE=0&SERVER_PROTOCOL=HTTP%2f1.1&SERVER_SOFTWARE=Microsoft-IIS%2f6.0&URL=%2fDefault.aspx&HTTP_CONNECTION=Keep-Alive&HTTP_ACCEPT=*%2f*&HTTP_ACCEPT_ENCODING=gzip%2c+deflate&HTTP_ACCEPT_LANGUAGE=zh-cn&HTTP_HOST=localhost%3a1234&HTTP_USER_AGENT=Mozilla%2f4.0+(compatible%3b+MSIE+7.0%3b+Windows+NT+5.2%3b+.NET+CLR+1.1.4322%3b+.NET+CLR+2.0.50727)&HTTP_UA_CPU=x86}

    Path: "/Default.aspx"

    PathInfo: ""

    PhysicalApplicationPath: "D://MyTest//WebSite1//"

    PhysicalPath: "D://MyTest//WebSite1//Default.aspx"

    QueryString: {}

    RawUrl: "/Default.aspx"

    RequestType: "GET"

    ServerVariables: {ALL_HTTP=HTTP_CONNECTION%3aKeep-Alive%0d%0aHTTP_ACCEPT%3a*%2f*%0d%0aHTTP_ACCEPT_ENCODING%3agzip%2c+deflate%0d%0aHTTP_ACCEPT_LANGUAGE%3azh-cn%0d%0aHTTP_HOST%3alocalhost%3a1234%0d%0aHTTP_USER_AGENT%3aMozilla%2f4.0+(compatible%3b+MSIE+7.0%3b+Windows+NT+5.2%3b+.NET+CLR+1.1.4322%3b+.NET+CLR+2.0.50727)%0d%0aHTTP_UA_CPU%3ax86%0d%0a&ALL_RAW=Connection%3a+Keep-Alive%0d%0aAccept%3a+*%2f*%0d%0aAccept-Encoding%3a+gzip%2c+deflate%0d%0aAccept-Language%3a+zh-cn%0d%0aHost%3a+localhost%3a1234%0d%0aUser-Agent%3a+Mozilla%2f4.0+(compatible%3b+MSIE+7.0%3b+Windows+NT+5.2%3b+.NET+CLR+1.1.4322%3b+.NET+CLR+2.0.50727)%0d%0aUA-CPU%3a+x86%0d%0a&APPL_MD_PATH=%2fLM%2fW3SVC%2f1860662192%2fRoot&APPL_PHYSICAL_PATH=D%3a%5cMyTest%5cWebSite1%5c&AUTH_TYPE=&AUTH_USER=&AUTH_PASSWORD=&LOGON_USER=&REMOTE_USER=&CERT_COOKIE=&CERT_FLAGS=&CERT_ISSUER=&CERT_KEYSIZE=&CERT_SECRETKEYSIZE=&CERT_SERIALNUMBER=&CERT_SERVER_ISSUER=&CERT_SERVER_SUBJECT=&CERT_SUBJECT=&CONTENT_LENGTH=0&CONTENT_TYPE=&GATEWAY_INTERFACE=CGI%2f1.1&HTTPS=off&HTTPS_K

EYSIZE=&HTTPS_SECRETKEYSIZE=&HTTPS_SERVER_ISSUER=&HTTPS_SERVER_SUBJECT=&INSTANCE_ID=1860662192&INSTANCE_META_PATH=%2fLM%2fW3SVC%2f1860662192&LOCAL_ADDR=127.0.0.1&PATH_INFO=%2fDefault.aspx&PATH_TRANSLATED=D%3a%5cMyTest%5cWebSite1%5cDefault.aspx&QUERY_STRING=&REMOTE_ADDR=127.0.0.1&REMOTE_HOST=127.0.0.1&REMOTE_PORT=46201&REQUEST_METHOD=GET&SCRIPT_NAME=%2fDefault.aspx&SERVER_NAME=localhost&SERVER_PORT=1234&SERVER_PORT_SECURE=0&SERVER_PROTOCOL=HTTP%2f1.1&SERVER_SOFTWARE=Microsoft-IIS%2f6.0&URL=%2fDefault.aspx&HTTP_CONNECTION=Keep-Alive&HTTP_ACCEPT=*%2f*&HTTP_ACCEPT_ENCODING=gzip%2c+deflate&HTTP_ACCEPT_LANGUAGE=zh-cn&HTTP_HOST=localhost%3a1234&HTTP_USER_AGENT=Mozilla%2f4.0+(compatible%3b+MSIE+7.0%3b+Windows+NT+5.2%3b+.NET+CLR+1.1.4322%3b+.NET+CLR+2.0.50727)&HTTP_UA_CPU=x86}

    TotalBytes: 0

    Url: {http://localhost:1234/Default.aspx}

    UrlReferrer: null

    UserAgent: "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.2; .NET CLR 1.1.4322; .NET CLR 2.0.50727)"

    UserHostAddress: "127.0.0.1"

    UserHostName: "127.0.0.1"

    UserLanguages: {Dimensions:[1]}

 

对于Response对象,你可能会看到如下内容:

代码段八:

    Buffer: true

    BufferOutput: true

    Cache: {System.Web.HttpCachePolicy}

    CacheControl: "private"

    Charset: "utf-8"

    ContentEncoding: {System.Text.UTF8Encoding}

    ContentType: "text/html"

    Cookies: {System.Web.HttpCookieCollection}

    Expires: 0

    ExpiresAbsolute: {0001-1-1 0:00:00}

    Filter: {System.Web.HttpResponseStreamFilterSink}

    HeaderEncoding: {System.Text.UTF8Encoding}

    IsClientConnected: true

    IsRequestBeingRedirected: false

    Output: {System.Web.HttpWriter}

    OutputStream: {System.Web.HttpResponseStream}

    RedirectLocation: null

    Status: "200 OK"

    StatusCode: 200

    StatusDescription: "OK"

    SuppressContent: false

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值