Home > ASP.NET > Asp.Net HttpRequest.Params

Asp.Net HttpRequest.Params

Ottiene un insieme combinato di elementi QueryString, Form, Cookies e ServerVariables.
In ASP.NET la proprietà Request.Params ritorna la collection degli elementi Form quali cookies, Server variables e Query String.
Per visualizzare i contenuti della collection è possibile utilizzare un blocco di codice di questo tipo :
Passaggio di valori tra pagine usando Request.Params

Elenco delle associazioni chiave/valore della Collection HttpRequest.Params
presente in System.Web.Configuration

<%@ Import Namespace="System.Web.Configuration" %>
..
string content = "<table cellpadding="0" cellspacing="0" style='width:98%;padding-right:10px;' border="1">";

NameValueCollection parColl = Request.Params;
for (int i = 0; i &lt;= parColl.Count - 1; i++)
{
   content += &quot;<tr><td width='20%'><small>k" + i + "</small><b>: "+ parColl.GetKey(i) + "</b></td>" ;

   string[] parValues = parColl.GetValues(i);
   if ( parColl.GetValues(i) != null )
   {
       content += "<td>";
       if ( parValues[0] != null )
       {
           for (int j = 0; j &lt;= parValues.Length - 1; j++)
           {
                 // content += &quot;Value &quot; + j + &quot;: <b>" + parValues[j] + "</b> <br />";
                 content += parValues[j] + " <br />";
            }
        }
        content += "</td>";
    }
    content += "</tr>";
}
content += "</table>";

..

questo l’output

portal registration qwy5dbafsvmpc0ygz40ezhar 100 HTTP_CONNECTION:keep-alive HTTP_CONTENT_LENGTH:0 HTTP_ACCEPT:text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 HTTP_ACCEPT_ENCODING:gzip, deflate HTTP_ACCEPT_LANGUAGE:en-us,en;q=0.5 HTTP_COOKIE:ASP.NET_SessionId=qwy5dbafsvmpc0ygz40ezhar; fontSize=100 HTTP_HOST:182.19.35.171 HTTP_REFERER:http://182.19.35.171/tmp/portal/sitemap HTTP_USER_AGENT:Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:15.0) Gecko/20100101 Firefox/15.0.1 Connection: keep-alive Content-Length: 0 Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 Accept-Encoding: gzip, deflate Accept-Language: en-us,en;q=0.5 Cookie: ASP.NET_SessionId=qwy5dbafsvmpc0ygz40ezhar; fontSize=100 Host: 182.19.35.171 Referer: http://182.19.35.171/tmp/portal/sitemap User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:15.0) Gecko/20100101 Firefox/15.0.1 /LM/W3SVC/3/ROOT/tmp E:\WWW\2010\it918\ 0 CGI/1.1 off 3 /LM/W3SVC/3 182.19.35.171 /tmp/pb.aspx E:\WWW\2010\it918\pb.aspx tab=portal&pg=registration 193.249.13.254 193.249.13.254 58774 GET /tmp/pb.aspx 182.19.35.171 80 0 HTTP/1.1 Microsoft-IIS/7.5 /tmp/pb.aspx keep-alive 0 text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 gzip, deflate en-us,en;q=0.5 ASP.NET_SessionId=qwy5dbafsvmpc0ygz40ezhar; fontSize=100 182.19.35.171 http://182.19.35.171/tmp/portal/sitemap Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:15.0) Gecko/20100101 Firefox/15.0.1 7.1.0871.0
k0: tab portal
k1: pg registration
k2: ASP.NET_SessionId qwy5dbafsvmpc0ygz40ezhar
k3: fontSize 100
k4: ALL_HTTP HTTP_CONNECTION:keep-alive HTTP_CONTENT_LENGTH:0 HTTP_ACCEPT:text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 HTTP_ACCEPT_ENCODING:gzip, deflate HTTP_ACCEPT_LANGUAGE:en-us,en;q=0.5 HTTP_COOKIE:ASP.NET_SessionId=qwy5dbafsvmpc0ygz40ezhar; fontSize=100 HTTP_HOST:182.19.35.171 HTTP_REFERER:http://182.19.35.171/tmp/portal/sitemap HTTP_USER_AGENT:Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:15.0) Gecko/20100101 Firefox/15.0.1
k5: ALL_RAW Connection: keep-alive Content-Length: 0 Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 Accept-Encoding: gzip, deflate Accept-Language: en-us,en;q=0.5 Cookie: ASP.NET_SessionId=qwy5dbafsvmpc0ygz40ezhar; fontSize=100 Host: 182.19.35.171 Referer: http://182.19.35.171/tmp/portal/sitemap User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:15.0) Gecko/20100101 Firefox/15.0.1
k6: APPL_MD_PATH /LM/W3SVC/3/ROOT/tmp
k7: APPL_PHYSICAL_PATH E:\WWW\2010\it918\
k8: AUTH_TYPE
k9: AUTH_USER
k10: AUTH_PASSWORD
k11: LOGON_USER
k12: REMOTE_USER
k13: CERT_COOKIE
k14: CERT_FLAGS
k15: CERT_ISSUER
k16: CERT_KEYSIZE
k17: CERT_SECRETKEYSIZE
k18: CERT_SERIALNUMBER
k19: CERT_SERVER_ISSUER
k20: CERT_SERVER_SUBJECT
k21: CERT_SUBJECT
k22: CONTENT_LENGTH 0
k23: CONTENT_TYPE
k24: GATEWAY_INTERFACE CGI/1.1
k25: HTTPS off
k26: HTTPS_KEYSIZE
k27: HTTPS_SECRETKEYSIZE
k28: HTTPS_SERVER_ISSUER
k29: HTTPS_SERVER_SUBJECT
k30: INSTANCE_ID 3
k31: INSTANCE_META_PATH /LM/W3SVC/3
k32: LOCAL_ADDR 182.19.35.171
k33: PATH_INFO /tmp/pb.aspx
k34: PATH_TRANSLATED E:\WWW\2010\it918\pb.aspx
k35: QUERY_STRING tab=portal&pg=registration
k36: REMOTE_ADDR 193.249.13.254
k37: REMOTE_HOST 193.249.13.254
k38: REMOTE_PORT 58774
k39: REQUEST_METHOD GET
k40: SCRIPT_NAME /tmp/pb.aspx
k41: SERVER_NAME 182.19.35.171
k42: SERVER_PORT 80
k43: SERVER_PORT_SECURE 0
k44: SERVER_PROTOCOL HTTP/1.1
k45: SERVER_SOFTWARE Microsoft-IIS/7.5
k46: URL /tmp/pb.aspx
k47: HTTP_CONNECTION keep-alive
k48: HTTP_CONTENT_LENGTH 0
k49: HTTP_ACCEPT text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
k50: HTTP_ACCEPT_ENCODING gzip, deflate
k51: HTTP_ACCEPT_LANGUAGE en-us,en;q=0.5
k52: HTTP_COOKIE ASP.NET_SessionId=qwy5dbafsvmpc0ygz40ezhar; fontSize=100
k53: HTTP_HOST 182.19.35.171
k54: HTTP_REFERER http://182.19.35.171/tmp/portal/sitemap
k55: HTTP_USER_AGENT Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:15.0) Gecko/20100101 Firefox/15.0.1
k56: IIS_UrlRewriteModule 7.1.0871.0

Passaggio di valori tra pagine usando Request.Params

E possibile utilizzare la collection Request.Params per passare valori tra una pagina e l’altra.

1° pagina blocco di codice per passare il valore

private void _myButton_Click(object sender, System.EventArgs e)
{					
	System.Collections.Specialized.NameValueCollection parCol = Request.Params; 
	string userEmail = Request.Params.Get("Email");			
	Server.Transfer("ConfirmPage.aspx"); 
}

2° pagina ConfirmPage.aspx codice per recuperare il valore passato

private void Page_Load(object sender, System.EventArgs e)
{
    if(Request.Params.Get("txtUserName") != null) 
    {
	string userName = Request.Params.Get("txtUserName"); 
	Response.Write(userName); 
    }
}
Advertisements
  1. Non c'è ancora nessun commento.
  1. No trackbacks yet.

Rispondi

Inserisci i tuoi dati qui sotto o clicca su un'icona per effettuare l'accesso:

Logo WordPress.com

Stai commentando usando il tuo account WordPress.com. Chiudi sessione / Modifica )

Foto Twitter

Stai commentando usando il tuo account Twitter. Chiudi sessione / Modifica )

Foto di Facebook

Stai commentando usando il tuo account Facebook. Chiudi sessione / Modifica )

Google+ photo

Stai commentando usando il tuo account Google+. Chiudi sessione / Modifica )

Connessione a %s...

%d blogger hanno fatto clic su Mi Piace per questo: