2012-05-15 33 views
0

當我作爲集合訪問Request對象時,它從哪裏獲取數據?Request []集合的內容是什麼

例如我知道

Request["someKey"] 

將返回的任

Request.QueryString["someKey"] 

Request.Form["someKey"] 

取決於所設置的值。

是否搜索到任何其他收藏(餅乾,會話)?

在幾個集合中存在關鍵值對會發生什麼?

我看了一下MSDN,但是找不到太多的信息。

http://msdn.microsoft.com/en-us/library/system.web.httpcontext.request

感謝您的幫助!

+0

您應該閱讀此鏈接http://msdn.microsoft.com/en-us/library/system.web.httprequest – jams

回答

1

如果您編譯該組件並看看源,它將在QueryString,然後Form,然後Cookies,然後ServerVariables,最後返回null如果他們沒有包含該項目之前。

public string this[string key] 
{ 
    get 
    { 
     string item = this.QueryString[key]; 
     if (item == null) 
     { 
      item = this.Form[key]; 
      if (item == null) 
      { 
       HttpCookie httpCookie = this.Cookies[key]; 
       if (httpCookie == null) 
       { 
        item = this.ServerVariables[key]; 
        if (item == null) 
        { 
         return null; 
        } 
        else 
        { 
         return item; 
        } 
       } 
       else 
       { 
        return httpCookie.Value; 
       } 
      } 
      else 
      { 
       return item; 
      } 
     } 
     else 
     { 
      return item; 
     } 
    } 
} 
+0

啊,多麼有趣。謝謝! 我不知道這裏有沒有官方文檔? –

+0

@Ev。將頁面的「trace」模式設置爲「true」 - 您將看到所有內容。例如'<%@ Page Trace =「true」%>' – EdSF